Skip to content

SADD, SREM, SMOVE and TYPE ask about one member, not the whole set - #3173

Open
matrixarkai wants to merge 2 commits into
mainfrom
perf/the-set-door-asks-one-member-not-the-set
Open

matrixarkai wants to merge 2 commits into
mainfrom
perf/the-set-door-asks-one-member-not-the-set

Conversation

@matrixarkai

Copy link
Copy Markdown
Owner

What changed

SADD, SREM, SMOVE and TYPE at the RESP door each listed every member of the set (SetMembers) to search it or to ask whether it was empty. They now ask SetIsMember per argument (SetCard for TYPE), the two read commands added in #3148. One shared helper (set_has_member) serves SADD, SREM and SMOVE. A member named twice in one SADD still counts once, because each add lands before the next lookup. No stored byte, log record or answer changes.

Allocations per door call (counting allocator, debug build, 20 calls averaged)

call before @20 members before @2,000 after @20 after @2,000
SADD of a member already present 38.0 2018.0 15.0 15.0
TYPE of a set 45.0 2025.0 23.0 23.0
whole-set listing (clone control) 24.0 2004.0

The control must grow by 1,000 or more between sizes or the probe fails, so it can see the dimension. Allocation counts only; instructions and wall time were not measured.

Plant

Reverting the door commit on a throwaway branch fails both guards: the_door_never_lists_the_set ("SADD listed the whole set") and the probe ("SADD spent 38.0 allocations at 20 members and 2018.0 at 2,000"). With the change restored both pass.

Tests (pinned by exact name in rust-ci.yml)

  • the_door_answers_what_it_always_answered: counts for duplicates, present and absent members, repeated removal, a move into the same key, TYPE of a set, an emptied set and nothing.
  • the_door_never_lists_the_set: records the commands the door issues; none is SetMembers, and the lookup it needs is issued.
  • probe::the_door_allocates_the_same_over_twenty_members_and_over_two_thousand (alloc-probe, ignored).

No limit is introduced. Not covered: SPOP, SRANDMEMBER, SSCAN and the set algebra commands still list the set.

Reused: SetIsMember and SetCard from #3148, the RESP test pattern, the alloc probe. Net: about 30 lines of door code changed, one 20-line helper, the rest tests.

🤖 Generated with Claude Code

superhaiou and others added 2 commits November 15, 2026 19:24
…he whole set

Each listed every member of the set (SetMembers) to search it or to ask
whether it was empty, so the cost followed the size of the set for an answer
about one member. They now issue SetIsMember per argument, and SetCard for
TYPE. A member named twice in one SADD still counts once because each add
lands before the next lookup.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… any size

Two default-build tests (answers, and the commands the door issues) and an
allocation probe with the whole-set listing as the clone control, all pinned
by exact name in rust-ci.yml.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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