Skip to content

feat(lru): productionize v1 and resolve 30 systems, concurrency, and algorithmic review findings - #3

Open
kislaykishore wants to merge 5 commits into
mainfrom
feat/productionize-v1
Open

kislaykishore wants to merge 5 commits into
mainfrom
feat/productionize-v1

Conversation

@kislaykishore

@kislaykishore kislaykishore commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Productionizes go-lru (MapCache, RadixCache, and ArenaRadixCache)

…flows, and docs

- Update module path to github.com/google/go-lru and package name to lru
- Add unified lru.New constructor with WithBackend (BackendMap, BackendRadix, BackendArenaRadix)
- Add StringValue, BytesValue, and generic SizedValue[T] / NewValue[T] helpers and runnable Example tests
- Add GitHub Actions CI workflows (.github/workflows/ci.yml and benchmarks.yml) and heap/compaction metrics
- Split README.md (<200 lines) and extract architecture.md and performance.md under docs/
- Add CHANGELOG.md and update .gitignore for release readiness

TAG=agy
CONV=04c870d6-3a21-4c5e-898b-8d984fda9190
…d CI

- Evict only the oversized entry in UpdateSize when entrySize + sizeDelta > maxSize and protect tail updates during critical pressure shedding (F-01)
- Use subtraction-based uint64 overflow guards in Insert and checkInvariants (F-02)
- Preserve zero-size entries during critical pressure shedding once byte target is reached (F-03)
- Strip trailing #hex artifacts across modified files and run go mod tidy (F-04)
- Guard against re-entrant MemoryPressureFunc callbacks via atomic samplingPressure flag (F-05)
- Restrict nilNode-2 pre-eviction to new-key insertions and reset pressure epoch on EraseEntriesWithGivenPrefix("") (F-06, F-07)
- Track expectedNodeMapLen and nodeMapDirty to prevent 64-bit FNV-1a hash collisions from triggering repeated O(N) compactions (F-08)
- Clone byte slices in BytesValue and new keys in mapCache.Insert (F-09)
- Optimize lock-free pressure reads, O(1) existing-key updates, zero-alloc edge splits, and O(subtree) incremental hashing in freeSubtree (F-10..F-16)
- Add regression_review_test.go covering F-01 through F-15

TAG=agy
CONV=254acf20-a371-4a1d-bbcd-30f97e769ac9
…dings

- Restrict foreground ArenaRadixCache auto-compaction to recycled free-list
  fragmentation (>=25% freed slots), eliminating O(N^2) slice reallocation
  thrashing on steady-state inserts under memory pressure.
- Synchronize lock-free pressure sampling across ArenaRadixCache, MapCache,
  and RadixCache using epoch-tagged pressure caches (cachedPressureEpoch,
  lastSampledEpoch), post-store reclaimEpoch re-verification, unlock-resample-relock
  loops on epoch mismatch, and overflow active-sampler goroutine ID tracking
  (overflowSamplingCount / overflowSamplingGIDs) to prevent re-entrant
  PressureFunc stack overflows under 3+ way concurrency.
- Replace O(N^2) tail re-scanning in shedAndCompactLocked with a single-pass
  victim cursor and implement proportional zero-size vs. positive-size entry
  shedding with watermark idempotence (lastReclaimedZeroCount).
- Fix UpdateSize upfront uint64 overflow checking, tail-to-target capacity
  lookahead (preventing premature collateral eviction of older entries), and
  non-MRU protected entry handling under critical memory pressure.
- Clone split prefixes (clonePrefix) in ArenaRadixCache and RadixCache to
  prevent intermediate routing nodes from pinning large evicted leaf key
  backing arrays, and restore the O(1) negative-lookup fast path in
  ArenaRadixCache via len(nodeMap) == len.
- Encapsulate BytesValue as an immutable, comparable struct, add .golangci.yml
  (v2) and goimports CI verification, and modernize all 10 test suites to
  stretchr/testify with Arrange-Act-Assert (AAA) structure and regression tests
  (TestRegression_F01-F15, TestRegression_R2_F01-F10, TestRegression_R3_F01-F04).

TAG=agy
CONV=81b87b88-6900-4de5-bef7-8a88ab422be8
@kislaykishore kislaykishore changed the title feat(lru): productionize github.com/google/go-lru v1.0.0 API, CI workflows, and docs feat(lru): productionize v1 and resolve 30 systems, concurrency, and algorithmic review findings Sep 25, 2026
- Pin actions/checkout@v4 to 11d5960a326750d5838078e36cf38b85af677262
- Pin actions/setup-go@v5 to 40f1582b2485089dde7abd97c1529aa768e1baff
- Pin golangci/golangci-lint-action@v7 to 9fae48acfc02a90574d7c304a1758ef9895495fa
- Pin actions/upload-artifact@v4 to ea165f8d65b6e75b540449e92b4886f43607fa02

TAG=agy
CONV=81b87b88-6900-4de5-bef7-8a88ab422be8
…hygiene review findings

- Move defer unlock and invariant checking after the unlocked epoch-mismatch
  resample loop in EvaluateMemoryPressure across MapCache, RadixCache, and
  ArenaRadixCache so panics in custom PressureFunc callbacks never double-unlock
  or run checkInvariants unlocked.
- Serialize pressure-state writers (storeSampledPressure, markReclaimedLocked,
  and maybeReclaimUnderPressureLocked) under pressureWriteMu while keeping reads
  lock-free, unconditionally clear cached pressure bits on re-entrant reclamation,
  and bound epoch-mismatch retry loops to retries < 2.
- Guard foregroundNoProtect sentinel capacity in ArenaRadixCache allocateNode and
  Insert, normalize foregroundNoProtect to nilNode in shedAndCompactLocked and
  maybeReclaimUnderPressureLocked, and reclaim peak arena/map slack when shedding
  or Insert pre-eviction drains a cache to empty.
- Clone strings in NewStringValue, zero removed entry fields in MapCache.eraseInternal,
  preserve non-empty Tier 1 windows for subnormal EvictionThreshold values, normalize
  -0.0 EvictionRetentionRatio, and add TestRegression_R5_F01 through TestRegression_R5_F08.

TAG=agy
CONV=504a869f-137c-432f-9731-f7dbf84d57b3
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