Repository navigation
Incrementally update StateCache weight on extend - #41396
stankiewicz wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR introduces StateCache.extend() and updates GlobalCachingStateHandler.extend() to use it, avoiding repeated full-list objsize.get_deep_size() traversals on every bundle commit when extending cached bag state. The implementation is clean, thread-safe, properly accounts for both the deep size of newly appended elements and the shallow container resize delta, and includes appropriate unit test coverage.
🔍 General Feedback
- Computing
get_deep_size(*elements)outside the cache lock while re-validating the cache entry under the lock matches the concurrency pattern used inget()andput(). - Measuring individual elements via
*elementsplus the container's shallow size delta accurately tracks the list's memory footprint in O(delta) time instead of O(N).
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41396 +/- ##
============================================
+ Coverage 59.17% 59.34% +0.17%
Complexity 4925 4925
============================================
Files 1462 1464 +2
Lines 186310 186972 +662
Branches 3669 3669
============================================
+ Hits 110247 110964 +717
+ Misses 72707 72652 -55
Partials 3356 3356
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @damccorm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Drop the redundant pre-sizing lock check and duplicate list copy in StateCache.extend, and restrict cached values to list so sys.getsizeof tracks container growth accurately. Keep missing and loading entries as a no-op because another worker thread can evict or reload the key while elements are sized outside the lock.
damccorm
left a comment
There was a problem hiding this comment.
Thanks, one more nit - feel free to address/merge
Co-authored-by: Danny McCormick <dannymccormick@google.com>
GlobalCachingStateHandler.extend() previously mutated cached list entries in place and re-inserted them via StateCache.put(), which ran objsize.get_deep_size() across the entire accumulated list on every bundle commit (quadratic O(B * N) deep GC referent traversal as a bag grows to N elements across B bundles).
Add StateCache.extend() to measure only the newly appended elements plus any list container resize delta when extending a cached list entry.