Solana - getProgramAccounts Performance Considerations

On Solana, the getProgramAccounts method allows you to fetch all accounts owned by a specific program, optionally filtered by additional criteria.

While powerful, this method is also very compute and resource-intensive, especially when called against large programs such as Solana’s Stake Program. As a result, response times can reach 10 seconds or more, depending on:

  • Program size – number of accounts to scan
  • Filters – or lack thereof
  • EncodingjsonParsed adds significant overhead compared to binary formats

Why getProgramAccounts Can Be Slow

  1. Full account scan
    The method must walk through all accounts owned by the target program. If the program has millions of accounts (like the Stake program), the node must process a large dataset.
  2. Complex filters
    Filters reduce the number of results returned but still require the node to evaluate each account against your filter rules.
  3. Heavy parsing (jsonParsed)
    When using "encoding": "jsonParsed", the node decodes raw binary data into human-readable JSON. This parsing is time consuming and increases response time.

How to Improve Performance

If you encounter slow responses (10s or more), consider these adjustments:

  • Use binary encoding instead of jsonParsed
    "encoding": "base64"
    
    Binary encodings are much lighter and avoid costly parsing overhead. You can decode the data on your side if necessary.
  • Apply additional filters
    Narrow the search space with multiple memcmp filters or data size filters to reduce the number of accounts evaluated.

Example: Encoding With base64

curl --location 'https://solana-mainnet.gateway.tatum.io' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
     "jsonrpc": "2.0",
     "id": 1,
     "method": "getProgramAccounts",
     "params": [
       "Stake11111111111111111111111111111111111111",
       {
         "filters": [
           {
             "memcmp": {
               "offset": 12,
               "bytes": "DRixSJFQVMJfRPoUthYMDMFgTJwYBg9aoL7U68pR1ejL"
             }
           }
         ],
         "encoding": "base64"
       }
     ]
   }'

Key Takeaways

  • getProgramAccounts is inherently heavy on large programs. Long response times are expected.
  • Using jsonParsed adds performance costs.
  • Better performance is achieved with binary encoding and well-designed filters.
  • For frequent queries, consider reducing call frequency and caching results when possible.