Skip to content

perf(miss-tracking): drop reply materialization for EmptyCollection arbitrary commands [RED-200840] - #469

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/red-200840-emptycollection-misstracking-perf
Jun 16, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/red-200840-emptycollection-misstracking-perf

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Arbitrary-command miss-tracking (--command-miss-tracking=auto, default-on since v2.4.x) forced set_keep_value(true) for EmptyCollection-shaped replies — HGETALL / SMEMBERS / LRANGE / .... That makes the protocol parser malloc + memcpy every element of every reply just to later check whether the top-level array was empty, costing 5–11% throughput on the hash datapath nightly and producing false 3%-baseline failures since build 7384 (RED-200840).

EmptyCollection only needs to know whether the reply's top-level aggregate is empty — not its contents. This PR captures the declared top-level aggregate length (*N / %N / ~N header) once per response in the parser (alloc-free, independent of keep_value) and classifies emptiness from it:

get_top_array_len() reply verdict
> 0 populated array/map/set hit
0 empty (*0) or null (*-1) miss
-1 not a top-level aggregate (scalar/bulk misshape) miss

This reproduces the previous get_mbulk_value() structural semantics exactly, while dropping the materialization.

Correctness

An interim get_hits()==0 approach was caught (by adversarial review) to regress two cases; the declared-length approach handles both correctly:

  • a collection of only zero-length elements (e.g. a set whose member is "") → hit, not miss (count comes from the header, not a per-value walk);
  • a non-array misshape → miss, matching the old top == NULL guard.

ArrayPerElementNulls (HMGET / MGET / ZMSCORE / GEOPOS) still materializes — it needs per-position nulls.

Testing

  • Builds clean.
  • Verified with the real binary against live redis: zero-length-member sets count as hits (~30% hit rate over keys 1–10 with 3 populated), missing keys as misses; populated HGETALL likewise.
  • Adds test_arbitrary_smembers_zero_length_member_is_hit regression test.

Notes / follow-ups

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 [email protected]


Note

Medium Risk
Touches the benchmark hot path and arbitrary-command miss accounting; behavior is intended to match prior semantics but parser edge cases (RESP3 push/attribute frames) are involved.

Overview
EmptyCollection miss tracking (e.g. SMEMBERS, HGETALL, LRANGE) no longer turns on set_keep_value(true), so those replies are not fully materialized on the hot path. Only ArrayPerElementNulls commands still force value keeping.

The RESP parser records the declared top-level aggregate length from the reply header (*N / %N / ~N) on protocol_response via get_top_array_len(). EmptyCollection hit/miss logic uses that count instead of walking get_mbulk_value(), so empty vs populated collections stay correct (including sets whose only member is an empty string) without malloc/memcpy per element.

Adds test_arbitrary_smembers_zero_length_member_is_hit to lock in declared-length behavior.

Reviewed by Cursor Bugbot for commit 1432068. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci

jit-ci Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

…rbitrary commands

Arbitrary-command miss-tracking (auto, default-on since v2.4.x) forced
set_keep_value(true) for EmptyCollection-shaped replies (HGETALL, SMEMBERS,
LRANGE, ...). That makes the protocol parser malloc + memcpy every element of
every reply just to later check whether the top-level array was empty, costing
5-11% throughput on the hash datapath nightly (RED-200840).

EmptyCollection only needs to know whether the reply's top-level aggregate is
empty, not its contents. Capture the declared top-level aggregate length
(*N / %N / ~N header) once per response in the parser -- alloc-free and
independent of keep_value -- and classify emptiness from it:

  get_top_array_len()  > 0  -> populated collection -> hit
                          0  -> empty (*0) or null (*-1) array -> miss
                         -1  -> reply was not a top-level aggregate -> miss

This reproduces the previous get_mbulk_value() structural semantics exactly,
including the two edge cases an interim get_hits()-based approach regressed:
  - a collection of only zero-length elements (e.g. a set member "") counts as
    a hit, not a miss (count comes from the header, not a per-value walk);
  - a non-array misshape counts as a miss, matching the old top==NULL guard.

HGETALL/SMEMBERS/LRANGE no longer materialize reply values; ArrayPerElementNulls
(HMGET/MGET/ZMSCORE/GEOPOS) still does, as it needs per-position nulls.

Adds a regression test for the zero-length-member case.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/red-200840-emptycollection-misstracking-perf branch from b87d08f to 1432068 Compare June 16, 2026 12:31
@fcostaoliveira
fcostaoliveira marked this pull request as ready for review June 16, 2026 12:57
@fcostaoliveira
fcostaoliveira merged commit 6a9bde1 into master Jun 16, 2026
122 checks passed
@fcostaoliveira
fcostaoliveira deleted the fix/red-200840-emptycollection-misstracking-perf branch June 16, 2026 14:36
fcostaoliveira added a commit that referenced this pull request Jun 16, 2026
…rbitrary commands (#469)

Arbitrary-command miss-tracking (auto, default-on since v2.4.x) forced
set_keep_value(true) for EmptyCollection-shaped replies (HGETALL, SMEMBERS,
LRANGE, ...). That makes the protocol parser malloc + memcpy every element of
every reply just to later check whether the top-level array was empty, costing
5-11% throughput on the hash datapath nightly (RED-200840).

EmptyCollection only needs to know whether the reply's top-level aggregate is
empty, not its contents. Capture the declared top-level aggregate length
(*N / %N / ~N header) once per response in the parser -- alloc-free and
independent of keep_value -- and classify emptiness from it:

  get_top_array_len()  > 0  -> populated collection -> hit
                          0  -> empty (*0) or null (*-1) array -> miss
                         -1  -> reply was not a top-level aggregate -> miss

This reproduces the previous get_mbulk_value() structural semantics exactly,
including the two edge cases an interim get_hits()-based approach regressed:
  - a collection of only zero-length elements (e.g. a set member "") counts as
    a hit, not a miss (count comes from the header, not a per-value walk);
  - a non-array misshape counts as a miss, matching the old top==NULL guard.

HGETALL/SMEMBERS/LRANGE no longer materialize reply values; ArrayPerElementNulls
(HMGET/MGET/ZMSCORE/GEOPOS) still does, as it needs per-position nulls.

Adds a regression test for the zero-length-member case.

Co-authored-by: Claude Opus 4.8 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Jun 16, 2026
…prometheus-exporter

Resolves tests/test_requirements.txt by keeping both new deps (prometheus_client
for the exporter suites + psutil for master's CPU cross-validation). Source files
(run_stats, client, memtier_benchmark) auto-merged; verified: both build flavors
compile, make check + format-check green, statsd wire test 4/4 (one-producer
refactor intact), live /metrics scrape 200.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

1 participant