Repository navigation
Optimize Fn Harness Caches - #41723
Optimize Fn Harness Caches #41723reuvenlax wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR significantly optimizes Caches and ClearableCache in the Java SDK Harness by introducing fast-path object weighing, lazy weight evaluation for CompositeKey and CompositeKeyPrefix on the lookup path, precomputed key hash codes, and reference-counted concurrent key tracking for ClearableCache. The changes are well-architected, thoroughly tested for concurrency/eviction edge cases, and accompanied by comprehensive JMH benchmarks.
🔍 General Feedback
- Lookup & Weighing Fast Paths: Deferring
CompositeKeyandCompositeKeyPrefixweight calculations until cache insertion and adding exact-class fast paths inCaches.weighavoid expensiveMemoryMeter.measureDeepreflection on cache hits and common immutable types. - Hash Distribution: Including
Objects.hashCode(key)inCompositeKey.hashCode()fixes a major hash collision bottleneck where all keys within the same sub-cache namespace previously hashed to the same bucket. ClearableCacheCorrectness & Concurrency: Replacing the non-thread-safeWeakHashMapwith the epoch-aware, reference-countedKeyTrackerandShrinkOnEvictionDekker checks properly handles nested sub-caches, evictions, and concurrentclear()operations without leaking tracked keys or resurrecting stale entries.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
@Abacn Also the hacky COMPACT_STRINGS codepath wasn't there for performance, it was to better estimate string sizes (in some cases today we can overestimate a string size by 2x in the cache). Since the impact is unclear on real pipelines, I'm removing this code for now and replacing with a comment. |
…y, ClearableCache key tracking)
d9fff73 to
7cdfee1
Compare
@Abacn I split off the Caches change, so you can test it in isolation.