How does the getProgramAccounts() scale as the number of accounts stored on the chain grows?
1 Answer
By default, getProgramAccounts
performs a linear scan over all accounts, so it will scale linearly with the number of alive accounts.
However, if you enable the --account-index program-id
, then solana indexes the accounts by program id using DashMap
(the index data structure is defined here: https://github.com/solana-labs/solana/blob/c4ec031daaa9c6650d37ec351fa680d1c92320be/runtime/src/secondary_index.rs#L103). Since it is a DashMap
which is a hashmap, performance in that case should be O(1)
for the lookup. So performance is independent from total number of accounts but of course the complexity is still linear in the number of returned accounts since each account needs to be loaded and sent over the network.