You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the LruCache implementation provided by hashlink instead of the current lru one.
This is mostly a 1-to-1 swap with only slight API incompatibilities.
I have decided to leave some config files which previously used NonZeroUsize but they may not be required anymore and could potentially switch to usize.
Additional Info
This also bumps hashlink to 0.11.
Once we update libp2p and discv5, it will remove lru as a dependency outside of the execution_engine_integration testing binary (brought in by alloy-provider).
Are there any benchmarks comparing lru to hashlink? Can you ask Claude to cook some up?
I got Claude to write some and here was its analysis (Disclaimer, I did not review the benchmarks):
Key Findings
hashlink is significantly faster for read operations (get, peek, contains_key, get_miss) — consistently 16-26% faster across all cache sizes. This is the most common operation in all hot paths.
lru is slightly faster for insert-with-eviction — about 2-3% faster, which is within noise for most scenarios.
lru is slightly faster for remove — about 5-7% at small sizes, converging at larger sizes.
The mixed-workload hot path simulations show lru winning — this is because the benchmarks include MediumValue allocation (256 bytes) in the entry().or_insert_with() / get_or_insert_mut() pattern. The hashlinkentry() API has slightly different ergonomics where the entry value construction may differ from lru's get_or_insert_mut. The data availability and block cache benchmarks show the biggest gap because they involve higher insert ratios with medium-sized values.
For the pre-finalization cache (hottest path), the two are essentially tied (~2% difference, within noise). This cache is dominated by contains_key which hashlink does faster, but the mix includes enough inserts to balance it out.
For the payload ID cache, hashlink is slightly faster — this is a get-heavy workload on a larger cache where hashlink's read advantage shines.
Verdict
The migration is reasonable from a performance perspective. The read-heavy workloads (which dominate in production — the caches are mostly read with occasional writes) favor hashlink. The mixed workloads with medium/large values show a small regression due to insert overhead, but these are not the hottest paths in absolute terms. The pre-finalization cache (the single hottest path) shows no meaningful difference.
This file contains hidden or 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
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.
Proposed Changes
Use the
LruCacheimplementation provided byhashlinkinstead of the currentlruone.This is mostly a 1-to-1 swap with only slight API incompatibilities.
I have decided to leave some config files which previously used
NonZeroUsizebut they may not be required anymore and could potentially switch tousize.Additional Info
This also bumps
hashlinkto0.11.Once we update
libp2panddiscv5, it will removelruas a dependency outside of theexecution_engine_integrationtesting binary (brought in byalloy-provider).