Skip to content

Account for shared strings proportionally in JSON memory usage - #1645

Merged
TalBarYakar merged 2 commits into
masterfrom
tal.ba/bug/mem_usage_prop
Oct 5, 2026
Merged

TalBarYakar merged 2 commits into
masterfrom
tal.ba/bug/mem_usage_prop

Conversation

@TalBarYakar

@TalBarYakar TalBarYakar commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

JSON memory reporting currently charges the full string allocation for every reference, even when multiple references share the same allocation. This change divides each string’s allocation size—including its header and padding—by its global reference count. Arrays and objects sum these contributions, retaining fractional bytes until the final result is rounded to an integer. Align Ijson


Note

Medium Risk
Changes how reported JSON key memory is computed for commands that use get_memory, which can shift monitoring and limits without affecting stored data.

Overview
JSON memory reporting no longer counts the full backing allocation for every copy of the same interned string. The ijson dependency is bumped so mem_allocated() splits each string’s allocation (including header/padding) by its global reference count and keeps fractional bytes while aggregating containers.

RedisIValueJsonKeyManager::get_memory now rounds (mem_allocated() + size_of::<IValue>()) as a float before returning bytes, matching that fractional accounting. A new unit test asserts that ten clones of one string each report one-tenth of the allocation, and that the sole survivor reports the full size again after the clones are dropped.

Reviewed by Cursor Bugbot for commit eb7f1b1. Bugbot is set up for automated code reviews on this repo. Configure here.

@TalBarYakar TalBarYakar self-assigned this Sep 27, 2026
@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.97%. Comparing base (c4e35c2) to head (1773290).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1645   +/-   ##
=======================================
  Coverage   85.97%   85.97%           
=======================================
  Files          15       15           
  Lines        5306     5306           
=======================================
  Hits         4562     4562           
  Misses        744      744           

☔ 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.

JSON memory reporting currently charges the full string allocation for every reference, even when multiple references share the same allocation.
This change divides each string’s allocation size—including its header and padding—by its global reference count. Arrays and objects sum these contributions, retaining fractional bytes until the final result is rounded to an integer.
Align Ijson
@TalBarYakar
TalBarYakar force-pushed the tal.ba/bug/mem_usage_prop branch from 1773290 to eb7f1b1 Compare October 5, 2026 06:15
@TalBarYakar
TalBarYakar merged commit fbe6eae into master Oct 5, 2026
56 of 59 checks passed
@TalBarYakar
TalBarYakar deleted the tal.ba/bug/mem_usage_prop branch October 5, 2026 06:57
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