Skip to content
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

feat(pkg/trie): Add TrieCache for trie values and nodes #3895

Merged
merged 116 commits into from
May 21, 2024

Conversation

dimartiro
Copy link
Contributor

@dimartiro dimartiro commented Apr 16, 2024

Changes

This PR introduces a TrieCache an LRU cache to reduce latency during trie lookups.

This implementation represents the simplest form of cache. In the future, we could consider a more complex one like parity does using different caches for different purposes, such as SharedTrieCache, LocalTrieCache, and TrieCache.
These could serve as inspiration for future enhancements to our caching strategy.
For further details, see Parity's cache implementation.

Summary of changes

  • New TrieCache interface
  • In-memory trie cache implementation
    • Tests
  • Start using TrieCache in TrieDB
    • Tests
  • Add benchmarking without cache vs with cache

Tests

make test

Benchmarks

Benchmark Iterations time / op bytes / op allocs / op
get_value_without_cache-12 208468 5960 ns/op 5609 B/op 167 allocs/op
get_value_with_cache-12 8990666 132.4 ns/op 116 B/op 4 allocs/op
iterate_all_entries_without_cache-12 32265 37454 ns/op 34783 B/op 1053 allocs/op
iterate_all_entries_with_cache-12 127227 9784 ns/op 7794 B/op 280 allocs/op

Issues

closes: #3623

Primary Reviewer

@EclesioMeloJunior

pkg/trie/cache/inmemory/trie_cache.go Outdated Show resolved Hide resolved
pkg/trie/cache/inmemory/lru_cache.go Outdated Show resolved Hide resolved
pkg/trie/cache/trie_cache.go Outdated Show resolved Hide resolved
Copy link
Member

@EclesioMeloJunior EclesioMeloJunior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

pkg/trie/cache/inmemory/lru_cache.go Outdated Show resolved Hide resolved
@dimartiro dimartiro requested a review from timwu20 May 10, 2024 14:51
@dimartiro dimartiro requested a review from timwu20 May 15, 2024 13:41
@dimartiro dimartiro requested a review from timwu20 May 20, 2024 01:07
@dimartiro dimartiro merged commit b0235ce into development May 21, 2024
24 checks passed
@dimartiro dimartiro deleted the diego/triedb-cache branch May 21, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-complex Complex changes across multiple modules. Possibly will require additional research. S-trie issues related to the pkg/trie package. T-feat this issue/pr is a new feature or functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(pkg/trie): Implement trie nodes / values cache
4 participants