feat(blockdb): add lru cache for block entries #4425
Draft
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.
Why this should be merged
I noticed that during C-Chain block execution testing, each block accepted will trigger 3 block fetches (header, body, and receipts) for each accepted block. This happens when collecting unflattened logs in the acceptor queue (code).
Fetching block data should be fast but decompressing the data each time adds a lot of overhead. This overhead can be completely avoided with an cache because the block data should have been just written to the database.
A cache was not originally added to blockdb because the VMs all have caches for blocks already. But they can be bypassed due to oversight and having a cache at the db level ensures these kind of issues are avoided.
How this works
Added an lru cache with a size of 256 for data entries.
Cache is keyed by block height and is updated on
PutandGet. This cache is used then checked onGetandHas.How this was tested
Unit tests and reexecution benchmark
Need to be documented in RELEASES.md?