-
Notifications
You must be signed in to change notification settings - Fork 21
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
cache polish #1039
cache polish #1039
Conversation
|
||
return result as any as T; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this will cause a timeout in getting Metadata. Blockscout will query the account balances of many block hashes. We can run Blockscout for a few days to test it.
@ntduan please review this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetching metadata in parallel should already be improved polkadot-js/api#4708, but yeah we can try and see how it actually goes
an ideal way would still be querying storage directly without decorating other parts, but better through api itself polkadot-js/api#6015 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1039 +/- ##
==========================================
+ Coverage 77.92% 78.04% +0.11%
==========================================
Files 54 55 +1
Lines 2718 2719 +1
Branches 635 631 -4
==========================================
+ Hits 2118 2122 +4
+ Misses 587 584 -3
Partials 13 13
|
Change
There seems to be a bug with our storage query helper, which is very random and cannot be reproduced (so far). Before we put too much bandwidth catching the tricky bug, we can use a slightly less optimized but more stable approach: classy way to query storage with apiAt.
Also:
Test
All tests still passed, also added tests to make sure cached request are much faster
Performance Analysis
These analysis are mostly in theory, we can see how it actually goes by taking a snapshot of current RPC performance, and compare.
There are two main steps for a storage call:
step 1
apiAt construction already has internal cache for
runtimeVersion => registries
, so the only repeated part is the decoration process. These local calculations should take much less time than waiting for the async call in step 2 (TBD).We can still alleviate repeated decoration by caching
blockHash => apiAt
. In practice most of the calls should be targeting recent blocks, caching only 100 apiAt could already have a sufficiently great hit rate, while maintaining a low memory footprint.step 2
We don't necessarily need to cache storage data, since the hit rate will likely be low. Each storage call queries for a specific block with very specific params, such as "nonce for address XXX at block YYY", which is not very likely to repeat.
On the other hand, cacheing
blockHash => *
should have a much better hit rate, such asblockHash => apiAt
mentioned above. We should also cache the (very) few common queries that are heavily repeated:blockNumber => blockHash
blockHash => blockData
blockHash => header
(implicitly cachedblockHash => blockNumber
)