Repository navigation
Probe IObject by &str without interning the key - #27
Closed
fcostaoliveira wants to merge 1 commit into
Closed
fcostaoliveira wants to merge 1 commit into
fcostaoliveira wants to merge 1 commit into
Conversation
ObjectIndex for &str used IString::intern(self) before every lookup, remove and mutable lookup: a cache-guard acquisition, a hash into the global string set, a refcount bump and, on a miss, an alloc/free pair, all before the object's own table was consulted. The table hashes key bytes, so a borrowed &str can probe it directly: a ProbeKey trait hashes the borrowed bytes with the same hasher and compares bytes against resident keys. Insertion (index_or_insert) still interns because it needs an owned key. No change to interning semantics: lookups never created cache entries that outlived the call. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Author
|
RedisJSON end-to-end results for this change are in: RedisJSON
Full record, raw memtier output and TMA trees: https://github.com/redis-performance/json-agent-workspace/blob/main/experiments/MODULE-001-redisjson-end-to-end/README.md 🤖 Generated with Claude Code |
Author
|
Closing. A re-measurement on this exact head still shows a benchmark or end-to-end row more than 3% worse than base, which is our bar for proposing a change. I will reopen or resubmit once that row is resolved. |
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
ObjectIndex for &strinterned the probe key before every lookup, mutable lookup and removal: a cache-guard acquisition, a hash into the global string set, a refcount bump and, on a miss, an allocation that the temporary's drop then freed, all before the object's own table was consulted. The table hashes key bytes, so a borrowed&strcan probe it directly.This PR adds a small
ProbeKeytrait with impls forIString(identity-first equality, as today) andstr(sameDefaultHasherover the bytes viastr::hash, byte equality againstresident.as_str()), makesfind_bucket_implgeneric over it, and routesindex_into,index_into_mutandremovefor&strthrough the borrowed probe.index_or_insertstill interns, because an insertion needs an owned key. Interning semantics are unchanged: a lookup never created a cache entry that outlived the call.In RedisJSON this is the path behind every JSON path step through an object (
json_path'sget_key) and every by-keyget/get_mutinivalue_manager.Measurements
Criterion microbenchmarks mirroring RedisJSON's call paths (
default-features = false, string cache initialised as OSS RedisJSON does, system allocator, release profile). Base and candidate are interleaved three times; the delta is the median over the three pairs, and the spread column is the base's own run-to-run spread.x86-64, Intel Sapphire Rapids (Xeon Platinum 8488C), Linux, bench pinned to one core, host idle
$.businesses[0].id)get_mut("field"))arm64, Apple M-series, macOS (same protocol, no pinning available): hits −30 to −46%, misses −48 to −83%, by-key mutations −10 to −39%, control +0.0%.
Memory: retained and peak bytes per fixture,
mem_allocated(), clone/serialise/CBOR sizes are identical to the baseline on every fixture; lookups allocate nothing before or after.TMA (Linux, toplev level 2, 20 s windows, CPU-pinned),
lookup/path-chain-yelp:The intern-cache round trip was the memory-bound part of a lookup; what remains is a core-bound hash and probe.
Things worth knowing
mem_allocated()tree walk, +4.0% on a 24 ns array insert/remove loop) across three interleaved pairs. Their TMA trees andnmplacement point at code layout rather than the change; the Apple host shows the same class of movement on different benchmarks. Flagging rather than hiding it.str::hashandIString'sas_str().hashfeedDefaultHasherthe same bytes, so a&strprobe lands in the bucket the stored key was hashed into.cargo test --lib -- --test-threads=1passes in both the default andthread_safeconfigurations.The benchmark suite and the full experiment record (including rejected variants) live in the
redis-performance/json-agent-workspacerepository, branchfcostaoliveira/add-optimize-overnight-skill, underexperiments/EXP-002-lookup-no-intern/.Note
Medium Risk
Touches core object lookup/removal logic with unsafe bucket indexing; behavior must stay aligned with existing hash/equality invariants, but scope is localized and insertion semantics are unchanged.
Overview
Read-only object key operations no longer call
IString::internon the lookup key. Instead they probe the object's hash table (or small-object linear scan) directly using borrowed&strbytes.The change introduces a
ProbeKeyabstraction and makesfind_bucket_implgeneric over it:IStringkeeps identity-first matching;&struses the sameDefaultHasherover the string bytes and compares withresident.as_str().find_bucket_strexposes that path, andObjectIndex for &str'sindex_into,index_into_mut, andremoveuse it end-to-end.index_or_insertstill interns, since insertion requires an owned key.This targets hot paths such as JSON path steps and by-key
get/get_mutin RedisJSON, cutting intern-cache work on hits and especially on misses.Reviewed by Cursor Bugbot for commit 4465316. Bugbot is set up for automated code reviews on this repo. Configure here.
RedisJSON impact by command
RedisJSON
9ca1c88built unchanged against pinnedijson(379dadf) and against this change (Cargo[patch]only), on a pinnedredis-server(x86-64, Intel Sapphire Rapids, Linux); memtier-c 16 -t 215 s runs (-c 1 -t 1for the 633 KB issue674 document; the yelp filter and$..namerows withredis-benchmark -c 16 --threads 2 -n 300000), three interleaved rounds per cell, base run-to-run spreads 0.3–5.1%. Only commands that moved by 3% or more are listed; everything else is within noise. Full record, raw memtier output and server TMA: MODULE-001 in json-agent-workspace.$.businesses[*].reviews[*].geo <GeoJSON feature>, 28 targets$.businesses[*].extra <26-key object>, 10 targets$.businesses[*].categories <GeoJSON feature>, 10 targets$.businesses[*] {"merged": <26-key object>}, 10 targets$.businesses[*].review_count 1, 10 targets$.businesses[?(@.avg_rating>=4.5)].nameyelp$.businesses[*].reviews[*].user_name, 28 leaves$..uidover the 633 KB issue674 document, 4,378 objects$.businesses[*].{name,city,review_count,avg_rating,zip})Unchanged (|Δ| < 3%, 9 of 18 workloads): JSON.GET:
$.message.codeon the 38 KB yelp doc,$.ResultSet.totalResultsAvailableyahoo2,$.[8].zerojsonsl-1,$whole 38 KB yelp document,$.ResultSet.totalResultsAvailableyahoo2 at pipeline 16,$..[?(@.uid==1198)].MD5ModelUIDissue674,$..nameyelp; JSON.SET:$.message.code 1yelp; JSON.NUMINCRBY:num $ 1. Single-path commands at pipeline 1 spend their time in protocol handling (server TMA identical across variants); the filter over 4,378 objects and the string-heavy serialisations spend theirs outside the lookup path.Every mover performs one key lookup per visited object (
json_pathget_key,follow_pathget_mut), the path this PR takes off the interning cache. Memory unchanged.🤖 Generated with Claude Code