MOD-17912 Improve get_index performance (backport to 8.10) - #1632
Conversation
* MOD-17912 Improve `get_index` performance * fmt (cherry picked from commit 21568f4)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.10 #1632 +/- ##
=======================================
Coverage 85.93% 85.93%
=======================================
Files 15 15
Lines 5275 5276 +1
=======================================
+ Hits 4533 4534 +1
Misses 742 742 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f366fb6. Configure here.
| @@ -1,2 +1,3 @@ | |||
| [toolchain] | |||
| channel = "1.92" | |||
| components = ["rust-analyzer"] No newline at end of file | |||
There was a problem hiding this comment.
Unrelated toolchain component change
Low Severity
This backport is scoped to the get_index performance fix, but rust-toolchain.toml also adds components = ["rust-analyzer"]. That IDE component is unrelated to the cherry-pick, is not installed by getrust.sh, and can trigger extra rustup installs in CI and local checkouts.
Reviewed by Cursor Bugbot for commit f366fb6. Configure here.


Backport of 21568f4 (#1631) to
8.10.IValue::get_indexwasarr.iter().nth(index).ArrayIterimplements onlynext(), sonth()falls back to theIteratordefault and walks the array one element at a time; on a packed typed array each skipped element is also materialized into an ownedIValue(a heap allocation). Reading a whole vector was therefore quadratic. This is the LLAPIgetAtpath RediSearch uses to ingest JSON vector fields — see RED-213492, where dim-1280 embeddings cost ~16 ms per vector and ~4,300 s of a ~4,500 s RDB load.Cherry-picked cleanly, no adaptation needed.
Test plan
cargo test -p json_path— passes (8.10)cargo fmt --checkclean🤖 Generated with Claude Code
Note
Medium Risk
Touches the hot JSON array indexing path used for vector ingest and RDB load. Behavior should match, but typed elements are now materialized via direct slice access rather than iteration.
Overview
Makes
IValue::get_indexO(1) by indexing the packed backing slice instead ofarr.iter().nth(index).The old iterator path walked (and allocated) every skipped element on typed arrays, so a full vector read was quadratic. That is the LLAPI
getAtpath RediSearch uses for JSON vector fields. Heterogeneous arrays still return borrowed values; typed numeric variants wrap a single ownedIValue.Adds coverage for heterogeneous, F32, and I64 arrays, plus out-of-range / non-array cases. Also lists
rust-analyzerinrust-toolchain.toml.Reviewed by Cursor Bugbot for commit f366fb6. Bugbot is set up for automated code reviews on this repo. Configure here.