7

How does the getProgramAccounts() scale as the number of accounts stored on the chain grows?

1
  • it would be helpful to elaborate this question with more details, such as motivation, examples, unexpected observations, etc
    – trent.sol
    Commented Jul 18, 2022 at 18:44

1 Answer 1

7

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.