-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance Issue of Storage Read using entries()
and entriesAt()
#4959
Comments
entries()
and entriesAt()
entries()
and entriesAt()
How have you implemented the first RPC call? Is this on the Node side? |
Yes, we basically use |
Ok, the RPC would be more effective. So what the
With this there are some caveats -
So in the case of entries, it will at best make 2 RPC calls (assuming < 250 keys) and depending on the map size it will generally have to do multiples to retrieve all information. This is not a speedy operation. Taking 4096 keys -
The iteration for the keys are obviously the same as on the Node side, no matter which method - it still needs to loop through the trie to retrieve all keys, so that overhead would be comparable. Getting all the data however is less effective from an API perspective, since even with small maps <= 250 values it needs at least 2 calls for the keys and then values. |
Is there a way to get the entire |
You can only retrieve via keys. There used to be state_getPairs which is deprecated (and I believe marked unsafe) - since it is unlimited, it was unbounded and then could also overrun the 16MB response limit, since it literally had some serious performance issues on the Node itself. |
Make sense! I guess I am asking is there a way we can do something more efficient on the node side. For example, leveraging the subtrie structure more efficiently. |
It is a bit out of my wheelhouse, but as far as I know it would still need to iterate through the trie to find the keys - there are child tries, e.g. as implemented in Polkadot crowdloans I'm not sure how these operate from an iteration perspective on the Node. (It certainly is much easier to drop it completely, but not sure if these are faster iteration-wise, my exposure to them is mostly on the RPCS which have similar key/values methods) |
My 2 cents is that you shouldn't be abusing a node like this. It just won't scale as the substrate DB is never optimized for reading items like this. You should be using a different indexed database for these kind of queries, and keep this DB in sync with your chain. |
Closing as answered. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query. |
Toolchain:
NodeJS
+Typescript
One of the core performance of
MantaPay
is fast syncing UTXOs from the ledger to users' wallets.The core data-structure that we implements on chain is a storage double map:
(https://github.com/Manta-Network/Manta/blob/manta/pallets/manta-pay/src/lib.rs#L147)
We tried two methods of syncing
Shards
.api.query.mantaPay.shards.entries()
.In theory, the second method should be much faster since it is able to download the entire storage tree. However, we find the first one has 3x performance advantage even downloading the entire storage map. Below is the benchmark data:
Shards
Sizeentries()
latency (ms)@jacogr @shawntabrizi would love to get your thoughts on why the performance disparity and whether we can improve query storage
entries()
performance.The text was updated successfully, but these errors were encountered: