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

[QUESTION] Is the pointer of the RedisObject being used or not when using embstr encoding? #11031

Closed
xiebruce opened this issue Jul 23, 2022 · 1 comment

Comments

@xiebruce
Copy link

xiebruce commented Jul 23, 2022

When we doing something like set name Jack in Redis, because the length of string "Jack" is less than 39Bytes(<3.2) or 44 Bytes(>=3.2), string "Jack" will be stored using the "embstr" encoding, sds object will be stored in the same memory block right after RedisObject.

This is the redisObject struct

typedef struct redisObject {
    unsigned type:4;
    unsigned encoding:4;
    unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or
                            * LFU data (least significant 8 bits frequency
                            * and most significant 16 bits access time). */
    int refcount;
    void *ptr;
} robj;

My question: is the pointer(*ptr) of the RedisObject that often use to point to sds obejct being used when using embstr encoding? because in this situation, the sds object stores right after the RedisObject, it seems that we don't need to use the pointer to find where the sds object is(I guess).

@oranagra
Copy link
Member

The pointer is used by all readers, who usually treat this object as a normal string, and don't have any special handling for embedded strings.
The purpose of this encoding type was to reduce heap allocations, not memory.
It probably also improve cache locality, and removing the excess pointer would further help here, but will require a lot of code to handle these in all the reading flows.
Note that it'll always save memory, since the allocator bins have fixed sizes.

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

No branches or pull requests

2 participants