-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
The problem/use-case that the feature addresses
When a set command (e.g. SADD myset 42) is called with an integer value and the set is listpack-encoded, the current flow unnecessarily converts integer → string → integer:
- The integer 42 is converted to a string ("42") stored in tmpbuf
- lpFind() is called with that string — internally lpFind then calls string2ll() to convert "42" back to an integer for comparison (src/listpack.c:633)
There is already an explicit TODO comment in src/t_set.c (line 168) acknowledging this:
"TODO: Create and use lpFindInteger; don't go via string."
Description of the feature
Create a new lpFindInteger(lp, p, value) function in src/listpack.c that accepts an int64_t directly and compares against integer-encoded listpack entries without any string conversion. Declare it in src/listpack.h and use it in setTypeAdd() when str == tmpbuf (i.e. the value came in as an integer).
Affected files:
- src/listpack.c — add lpFindInteger()
- src/listpack.h — declare it
- src/t_set.c — use it and remove the TODO comment
Alternatives you've considered
No alternatives — the TODO in the source code already points to this exact approach.
Additional information
This is a small, self-contained performance improvement for integer-heavy listpack-encoded sets. Good first contribution from my side