Repository navigation
perf(miss-tracking): alloc-free per-position tracking for ArrayPerElementNulls (HMGET) [RED-200840] - #470
Closed
fcostaoliveira wants to merge 1 commit into
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
fcostaoliveira
force-pushed
the
fix/red-200840-emptycollection-misstracking-perf
branch
from
June 16, 2026 12:31
b87d08f to
1432068
Compare
…mentNulls The arbitrary-command miss-tracking for ArrayPerElementNulls replies (HMGET/MGET/ZMSCORE/GEOPOS/...) forced set_keep_value(true), materializing the entire reply tree -- a malloc+memcpy per element plus an mbulk/bulk_el node per element -- purely to attribute hits/misses per position. For small values the per-element node allocation, not the value copy, dominates, so this cost ~37% throughput / ~80% client CPU per op on HMGET (RED-200840, lab-confirmed). Replace the materialized walk with a per-top-level-element hit bitmap recorded directly by the parser (set_track_elem_misses): one uint8_t per element into m_last_response.m_elem_hits, no value copy, no node tree. Hit/miss is known at parse time: - bulk leaf: hit iff $N with N>0 (null $-1 and empty $0 are misses); - single-type leaf: hit unless RESP3 null '_'; - nested sub-array element: hit iff non-empty (*0/*-1 are misses). Nesting is handled with a single counter (m_nested_remaining) that tracks outstanding leaf slots in the current top-level element's subtree, so only direct children of the top-level array are recorded -- no frame stack, any depth. The client reads the bitmap instead of walking get_mbulk_value(); a non-array reply (top_array_len<0) still yields one miss bucket, exactly as the old get_mbulk_value()==NULL guard did. Verified deterministically (key-maximum=1) that per-position hit/miss is identical to the materialized walk for HMGET, MGET, and nested GEOPOS, under both RESP2 and RESP3. Co-Authored-By: Claude Opus 4.8 <[email protected]>
fcostaoliveira
force-pushed
the
fix/red-200840-hmget-allocfree-misstracking
branch
from
June 16, 2026 12:31
fc00cfc to
1bf5d3b
Compare
fcostaoliveira
marked this pull request as ready for review
June 16, 2026 12:57
fcostaoliveira
deleted the branch
fix/red-200840-emptycollection-misstracking-perf
June 16, 2026 14:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #469 (stacked on it). Fixes the HMGET half of the RED-200840 regression.
ArrayPerElementNullsreplies (HMGET / MGET / ZMSCORE / GEOPOS / ...) forcedset_keep_value(true), materializing the whole reply tree — amalloc+memcpyper element plus anmbulk/bulk_elnode per element — purely to attribute hits/misses per position. For small values the per-element node allocation dominates, so #469 (which only addressed the EmptyCollection/HGETALL path) left HMGET regressed.This PR replaces the materialized walk with a per-top-level-element hit bitmap recorded directly by the parser (
set_track_elem_misses): oneuint8_tper element intoprotocol_response::m_elem_hits— no value copy, no node tree. Hit/miss is known at parse time:$N, N>0 (null$-1and empty$0are misses);_;*0/*-1are misses).Nesting uses a single counter (
m_nested_remaining) tracking outstanding leaf slots in the current top-level element's subtree, so only direct children of the top array are recorded — no frame stack, any depth.Lab results (Granite Rapids, single-core client, pipeline=64, 40-field hashes, N=5 interleaved)
HMGET throughput restored to within ~2% of 2.2.1; HGETALL stays fixed.
Correctness
Verified deterministically (
--key-maximum=1, fixed keys) that per-position hit/miss is identical to the old materialized walk for HMGET (mixed present/absent fields), MGET (multi-key spec), and nested GEOPOS — under both RESP2 and RESP3 (the_null path). The existingtests/test_arbitrary_command_misses.pysuite (flat + GEOPOS-nested + RESP3-nil cases) covers these shapes.Notes
per_key_hitvector; throughput is effectively at baseline. A further micro-opt (reuse theper_key_hitscratch / skip per-position when no JSON out-file) is possible but diminishing returns.🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.8 [email protected]
Note
Medium Risk
Changes the hot-path RESP parser and arbitrary-command miss accounting for multi-element replies; behavior is intended to match the prior materialized walk but any parsing edge case could skew per-position stats.
Overview
ArrayPerElementNulls miss tracking (HMGET, MGET, ZMSCORE, GEOPOS, etc.) no longer turns on
set_keep_value(true)to build and walk a full reply tree. Connections that need per-position hits now useset_track_elem_misses(true), and the Redis parser records a compactm_elem_hitsbitmap while parsing.The parser adds
track_leafand am_nested_remainingcounter so only top-level array slots get a hit/miss flag (bulks, RESP3_, nested non-empty sub-arrays), matching the old walk without malloc/memcpy or per-element nodes.client::handle_responseforReplyShape::ArrayPerElementNullscopies that bitmap intoper_key_hitinstead of inspectingget_mbulk_value().SCAN and other paths that still need full replies keep
set_keep_valueonly where required; EmptyCollection and other shapes are unchanged.Reviewed by Cursor Bugbot for commit 1bf5d3b. Bugbot is set up for automated code reviews on this repo. Configure here.