Solana - getProgramAccounts Performance Considerations

getProgramAccounts scans every account a program owns, so calls on large programs can take 10 seconds or more; base64 encoding and filters speed them up.

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
  • Encoding – jsonParsed 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"
       }
     ]
   }'

Error -32010: excluded from account secondary indexes

A complex getProgramAccounts call can fail with the following error:

{
 "jsonrpc":"2.0",
 "error":{
  "code":-32010,
  "message":"Tokenkeg####### excluded from account secondary indexes; this RPC method unavailable for key"
 },
 "id":1
}

The error appears when a program is excluded from the node's secondary indexes. RPC nodes can exclude programs with many accounts, such as Tokenkeg..., from getProgramAccounts, so the method is unavailable for that program's key. To get a wallet's token balance without getProgramAccounts, call getTokenAccountsByOwner with the token's mint, as shown in Solana "Too many accounts requested" error and fix.

For background, see the Solana Program Library issue on GitHub.


Long response times for large blocks

Responses from Solana nodes sometimes take several seconds. One of the main reasons is the response size: depending on the block you query, the response can be 5–10 MB.

To reduce the transfer size, add an Accept-Encoding: gzip, br header to your requests. See Improving RPC Performance with Compression.


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.

Did this page help you?