Skip to content

feat(cache): add the arena-backed radix tree cache implementation #4878

Open
vedantdas-source wants to merge 5 commits into
radix-trie-cachefrom
optimize-radix
Open

feat(cache): add the arena-backed radix tree cache implementation #4878
vedantdas-source wants to merge 5 commits into
radix-trie-cachefrom
optimize-radix

Conversation

@vedantdas-source

@vedantdas-source vedantdas-source commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR introduces initial structure of the arenaRadix cache.

To reduce memory footprint and garbage collection overhead, this implementation moves away from traditional pointer-based nodes. Instead, it utilizes a Left-Child Right-Sibling (LCRS) representation backed by a slice-based arena allocator ([]arenaRadixNode) and 32-bit indices.

Changes made

  • added arenaRadixNode and arenaRadix core structs.
  • Internal arena memory management via a custom freelist (allocateNode, freeNode), entirely eliminating heap allocations during tree node creation.
  • Helper utilities for deterministic key hashing and full path reconstruction.

Link to the issue in case of a bug fix.

NA

Testing details

  1. Manual - NA
  2. Unit tests - Added a comprehensive suite in arena_radix_test.go to explicitly verify the internal tree mechanics and lru operations
  3. Integration tests - NA

Any backward incompatible change? If so, please explain.

None. This PR introduces new internal logic alongside the existing implementations and does not yet mutate any public package APIs or interfaces.

@vedantdas-source
vedantdas-source requested a review from a team as a code owner July 14, 2026 06:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a custom radix tree implementation (arenaRadix) using a Left-Child Right-Sibling (LCRS) representation and 32-bit indices to minimize slice allocations and pointer overhead, along with comprehensive unit tests. The feedback is minor, pointing out a typo ('capcacity') in a panic message within the node allocation logic.

Comment thread internal/cache/lru/arena_radix.go Outdated
@vedantdas-source
vedantdas-source force-pushed the optimize-radix branch 3 times, most recently from 0936c46 to 5a03406 Compare July 14, 2026 07:04
@vedantdas-source vedantdas-source changed the title feat(cache): added the core structure of arena-backed radix tree feat(cache): add the core structure of arena-backed radix tree Jul 14, 2026
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.77489% with 19 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (radix-trie-cache@dce6bfb). Learn more about missing BASE report.

Files with missing lines Patch % Lines
internal/cache/lru/arena_radix.go 91.77% 11 Missing and 8 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##             radix-trie-cache    #4878   +/-   ##
===================================================
  Coverage                    ?   83.90%           
===================================================
  Files                       ?      172           
  Lines                       ?    21504           
  Branches                    ?        0           
===================================================
  Hits                        ?    18042           
  Misses                      ?     2788           
  Partials                    ?      674           
Flag Coverage Δ
unittests 83.90% <91.77%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kislaykishore

Copy link
Copy Markdown
Collaborator

Please add the LRU implementation too in the same PR and ensure that the tests that pass with other LRU implementations pass with this one as well.

Comment thread internal/cache/lru/arena_radix.go Outdated
Comment thread internal/cache/lru/arena_radix.go Outdated
Comment thread internal/cache/lru/arena_radix.go Outdated
Comment thread internal/cache/lru/arena_radix.go Outdated
Comment thread internal/cache/lru/arena_radix.go Outdated
@vedantdas-source

Copy link
Copy Markdown
Collaborator Author

Please add the LRU implementation too in the same PR and ensure that the tests that pass with other LRU implementations pass with this one as well.

Done. Added the functionality of the LRU operations as well as tests that the existing lru cache are tested against.

@vedantdas-source
vedantdas-source force-pushed the optimize-radix branch 2 times, most recently from 468be24 to 77ba07b Compare July 17, 2026 11:57
@vedantdas-source vedantdas-source changed the title feat(cache): add the core structure of arena-backed radix tree feat(cache): add the arena-backed radix tree cache implementation Jul 17, 2026
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.

2 participants