Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: update examples on two JSON pages #1305

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

DEV: update examples on two JSON pages #1305

wants to merge 1 commit into from

Conversation

dwdougherty
Copy link
Collaborator

@dwdougherty dwdougherty commented Mar 20, 2025

DOC-5003

@LiorKogan:

I've updated the return values from each example on the two modified pages using the latest available Redis Stack Docker image. What I can't work out is how the values stack. For example, in the following sequence of commands,

127.0.0.1:6379> JSON.SET arr . '[""]'
OK
127.0.0.1:6379> JSON.DEBUG MEMORY arr
(integer) 64

the size, if I believe the current write-up, should be 8 + 8 = 16 bytes. But, inexplicably, it's 64 bytes. I don't know how that result is calculated. So, I'll need your help with the sizing explanations in the content/develop/data-types/json/ram.md document.

@dwdougherty dwdougherty added bug Something isn't working dev labels Mar 20, 2025
@dwdougherty dwdougherty requested a review from LiorKogan March 20, 2025 20:38
@dwdougherty dwdougherty self-assigned this Mar 20, 2025
@LiorKogan
Copy link
Member

@eranhd can you help here?

@ephraimfeldblum
Copy link

ephraimfeldblum commented Mar 23, 2025

@dwdougherty no, it could not be 8 + 8.

The size of an empty array is 8 because it consists only of a pointer to a static "null" array. if it is non-empty, we need to store the additional metadata info (size, capacity) which is 16 more bytes.

Why it's 64 and not 32, I'll investigate. (Although it might just be as simple as the array having extra unused capacity.)

@ephraimfeldblum
Copy link

Yes, the array is created with default capacity 4. I did not investigate why. That leaves us with 56 bytes of used memory.

The additional 8 bytes comes from, as far as I can tell, a mistaken double counting of the string. It is being counted once when accounting for the used capacity of the array, and being counted again when recursively counting the memory consumed by the values stored in the array.

@LiorKogan @eranhd this should probably be fixed.

@ephraimfeldblum
Copy link

The expected behavior should be

127.0.0.1:6379> json.set a . '["", ""]'
OK
127.0.0.1:6379> json.debug memory a
(integer) 56
127.0.0.1:6379> json.set a . '["", "", ""]'
OK
127.0.0.1:6379> json.debug memory a
(integer) 56
127.0.0.1:6379> json.set a . '["", "", "", ""]'
OK
127.0.0.1:6379> json.debug memory a
(integer) 56
127.0.0.1:6379> json.set a . '["", "", "", "", ""]'
OK
127.0.0.1:6379> json.debug memory a
(integer) 88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants