Skip to content

Add lpFindInteger() to avoid string conversion when searching integers in listpack-encoded sets #3408

@liveprasad

Description

@liveprasad

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:

  1. The integer 42 is converted to a string ("42") stored in tmpbuf
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions