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: Implement a memoization-based cache #30

Merged
merged 5 commits into from
Dec 13, 2023
Merged

Conversation

matheus23
Copy link
Member

@matheus23 matheus23 commented Aug 31, 2023

This is a performance optimization for CAR mirror.

This helps, especially when DAGs are huge, blockstores are locally slow (e.g. reading from disk) and when latency is not the main issue anymore.

It improves benchmarks quite a bit:
image


What this PR is doing is simply implementing one version of #28: A cache for block references: Cid -> Vec<Cid>.
This way, when there's a cache hit, we don't even need to fetch the block, parse it and find links. Instead, we get further references directly.

In some cases, this means running the same operation twice won't fetch any block from the blockstore at all.

Since different environments will want to implement different types of caches (e.g. the quick-cache based cache won't work in Wasm), the cache implementation is abstracted behind a trait Cache.

I've bundled two implementations: NoCache that simply always re-computed the value (no memoization), and InMemoryCache which uses the quick_cache library.


This PR depends on #29

@matheus23 matheus23 self-assigned this Aug 31, 2023
Base automatically changed from matheus23/tracing to main September 1, 2023 09:53
@matheus23 matheus23 mentioned this pull request Sep 4, 2023
@matheus23
Copy link
Member Author

Closes #28

@matheus23 matheus23 merged commit 01b127f into main Dec 13, 2023
9 checks passed
@matheus23 matheus23 deleted the matheus23/memoization branch December 13, 2023 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant