Skip to content

MOD-17912 Improve get_index performance (backport to 8.4) - #1635

Merged
AvivDavid23 merged 1 commit into
8.4from
cherry-pick-21568f4e-to-8.4
Aug 23, 2026
Merged

AvivDavid23 merged 1 commit into
8.4from
cherry-pick-21568f4e-to-8.4

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Backport of 21568f4 (#1631) to 8.4.

IValue::get_index was arr.iter().nth(index). ArrayIter implements only next(), so nth() falls back to the Iterator default and walks the array one element at a time; on a packed typed array each skipped element is also materialized into an owned IValue (a heap allocation). Reading a whole vector was therefore quadratic. This is the LLAPI getAt path 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.

Adaptations for 8.4:

  • Test rewritten for this branch's SelectValue API: get_long/get_double/as_str are non-Option here, and JSONArrayType/get_array_type (V7 getArray, 8.8+) do not exist — the packed-array assertion uses ijson's ArraySliceRef::is_typed instead.
  • rust-toolchain.toml hunk from the master commit dropped (conflicted; 8.4 pins channel 1.88).

The fix itself is byte-identical to master; the ijson pinned here (5676f592) has the same ArraySliceRef variants.

Test plan

  • cargo test -p json_path — passes (8.4)
  • cargo fmt --check clean
  • CI

🤖 Generated with Claude Code


Note

Medium Risk
Touches the JSON get_index path used for vector-field ingest, so a mismatch in typed-array handling could change element values or miss indices. The change is small, localized, and covered by unit tests.

Overview
Fixes quadratic IValue::get_index on packed typed arrays. The old arr.iter().nth(index) walk materialized each skipped element, which made full reads of JSON vector fields (RediSearch getAt) extremely slow.

Indexing now uses ArraySliceRef O(1) get for heterogeneous and typed numeric slices (i8–f64). Typed elements are wrapped as owned IValues; heterogeneous ones stay borrowed.

Adds a unit test covering typed floats/longs, mixed arrays, OOB, and non-arrays.

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

* MOD-17912 Improve `get_index` performance

* fmt

(cherry picked from commit 21568f4)
Test adapted to the 8.4 SelectValue API: get_long/get_double/as_str are
non-Option there, and JSONArrayType/get_array_type (V7 getArray, 8.8+) do not
exist, so the packed-array assertion uses ijson's ArraySliceRef::is_typed.
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.01%. Comparing base (7d00e74) to head (53eab8e).
⚠️ Report is 26 commits behind head on 8.4.

Additional details and impacted files
@@            Coverage Diff             @@
##              8.4    #1635      +/-   ##
==========================================
- Coverage   77.56%   77.01%   -0.55%     
==========================================
  Files          16       15       -1     
  Lines        3945     3803     -142     
==========================================
- Hits         3060     2929     -131     
+ Misses        885      874      -11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AvivDavid23
AvivDavid23 merged commit 6b1868b into 8.4 Aug 23, 2026
60 checks passed
@AvivDavid23
AvivDavid23 deleted the cherry-pick-21568f4e-to-8.4 branch August 23, 2026 07:50
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