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
- Encoding –
jsonParsed
adds significant overhead compared to binary formats
Why getProgramAccounts
Can Be Slow
getProgramAccounts
Can Be Slow- 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. - Complex filters
Filters reduce the number of results returned but still require the node to evaluate each account against your filter rules. - 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
Binary encodings are much lighter and avoid costly parsing overhead. You can decode the data on your side if necessary."encoding": "base64"
- Apply additional filters
Narrow the search space with multiplememcmp
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.
Updated about 3 hours ago