feat(db): add MDBX put-append for fast ordered puts #18603
+98
−22
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.
We only want 2 things in life:
This led us to
DatabaseProvider::insert_block
, which is still using put-upsert instead of put-append for tables with naturally increasing keys (likeBlockNumber
) in the happy/hot paths. For example:reth/crates/storage/provider/src/providers/database/provider.rs
Lines 2747 to 2755 in 4ddf3dd
This PR first adds
DbTxMut::append
with the optimised implementation for MDBX, and a benchmark to show how put-append is much faster than put-upsert in this scenario:Actual integration into key paths should be done in separate PRs with proper testing and benchmarks. Some places may be able to simply fall back to
put
, while others may want to report an error for different handling if the key is unexpectedly not the highest.