-
Notifications
You must be signed in to change notification settings - Fork 689
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
[wip]perf: cache block related data in ChainStore
#13006
Draft
mooori
wants to merge
10
commits into
near:master
Choose a base branch
from
mooori:chainstore-cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−4
Draft
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a5b9142
Caches for `header, hash_by_height`
mooori 859d5ee
Add block cache
mooori 6accccd
Add block to cache in `ChainStoreUpdate::finalize`
mooori 6f0eca1
Enable block cache in apply-range
mooori 532a955
Enable block_header cache in apply-range
mooori f175a17
Explain why multiple caches
mooori dd846aa
cleanup
mooori 59a1e7a
Make gc of blocks clear block cache
mooori 4215951
Cache `block_hash_by_height`
mooori b27b806
clippy
mooori File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FWIW I think it might make more sense to maintain a view of the most recent blocks in memory (pending analysis into access patterns), rather than caching separate queries and trying to implement something like LRU-evicted access-based cache here.
This would among other things potentially make the cache maintenance somewhat more straightforward and easier to reason about. First, because the only place where the block information is written is in
ChainStoreUpdate::finalize
, so this is where we'd update the cache too. And second is because some stray query (which can happen due to these queries being dependent on the user input) for a block from yesterday ago wouldn't affect the happy path.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.
After making
ChainStoreUpdate::finalize
update the cache, I tried to returncache.block(h).header()
fromget_block_header
. That made a lot of tests fail and turns out some columns get special treatment infinalize
or garbage collection. So the safest way might be to have a separate cache for eachDBCol
, even if it's a bit of a pain to handle. See the comment onChainStoreCache
.The
apply-range
command doesn't triggerChainStoreUpdate::finalize
. I suppose finding a way to do it manually or to otherwise populate the caches forapply-range
shouldn't be too hard. As a temporary workaround I'm inserting cache-missed data inget_block, ...
into the cache. More details in the comments.