Skip to content

[MOD-10084] port metric iterator to rust#6983

Merged
BenGoldberger merged 109 commits intomasterfrom
beng-rust-metric-iterator
Nov 4, 2025
Merged

[MOD-10084] port metric iterator to rust#6983
BenGoldberger merged 109 commits intomasterfrom
beng-rust-metric-iterator

Conversation

@BenGoldberger
Copy link
Collaborator

@BenGoldberger BenGoldberger commented Oct 6, 2025

add the metric iterator implementation in rust

Iterator - Metric - Read Dense/C    time:   [20.131 ms 21.760 ms 23.450 ms]
Iterator - Metric - Read Dense/Rust time:   [11.689 ms 11.726 ms 11.771 ms]

Iterator - Metric - Read Sparse/C    time:   [1.0607 ms 1.0628 ms 1.0664 ms]
Iterator - Metric - Read Sparse/Rust time:   [11.645 ms 11.652 ms 11.660 ms]

Iterator - Metric - SkipTo Dense/C    time:   [137.25 µs 138.99 µs 142.01 µs]
Iterator - Metric - SkipTo Dense/Rust time:   [224.61 µs 225.13 µs 225.67 µs]

Iterator - Metric - SkipTo Sparse/C    time:   [5.1269 ms 5.1291 ms 5.1311 ms]
Iterator - Metric - SkipTo Sparse/Rust time:   [17.315 ms 17.324 ms 17.334 ms]

Note

Introduces a Rust Metric iterator (with C interop), updates IdList helpers, exposes metric reset/array length symbols, and adds tests/benchmarks plus minor build/linking tweaks.

  • Rust Iterators (rqe_iterators):
    • Add metric::Metric iterator yielding metric results and attaching RSYieldableMetric values.
    • Enhance id_list::IdList with read_and_get_offset/skip_to_and_get_offset to support metric iterator.
    • New tests (tests/metric.rs) with C symbol mocks; feature-gated build script links arr for tests.
  • Benchmarks (rqe_iterators_bencher):
    • Add Metric iterator benchmarks and wire into benches/iterators.rs.
    • Extend C FFI wrapper with QueryIterator::new_metric and required symbols.
  • C/FFI:
    • Export ResultMetrics_Reset_func(RSIndexResult*) and bind it in Rust (inverted_index re-exports).
    • Expose array_len_func in util/arr and include arr.h in Rust FFI bindings; add C++ test for it.
    • Provide RSValue/metrics free/reset stubs in tests/benchers to manage metric values.
  • Build:
    • In build.sh, on non-macos add -C link-args=-lgcov for coverage; minor RUSTFLAGS invocation tweak.

Written by Cursor Bugbot for commit ce7e57e. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added the size:M label Oct 6, 2025
@BenGoldberger BenGoldberger changed the title Beng-rust-metric-iterator [MOD-10084] Beng-rust-metric-iterator Oct 13, 2025
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 91.75258% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.15%. Comparing base (e777a29) to head (ce7e57e).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/redisearch_rs/rqe_iterators/src/metric.rs 94.20% 2 Missing and 2 partials ⚠️
src/index_result.c 0.00% 2 Missing ⚠️
src/redisearch_rs/rqe_iterators/src/id_list.rs 91.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6983      +/-   ##
==========================================
- Coverage   85.41%   85.15%   -0.26%     
==========================================
  Files         337      340       +3     
  Lines       51920    52234     +314     
  Branches    11848    12157     +309     
==========================================
+ Hits        44345    44480     +135     
- Misses       7390     7566     +176     
- Partials      185      188       +3     
Flag Coverage Δ
flow 84.11% <0.00%> (-0.13%) ⬇️
unit 52.01% <91.75%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@gdesmott gdesmott force-pushed the beng-rust-metric-iterator branch from 0b6783c to ecc8157 Compare November 3, 2025 11:44
@gdesmott
Copy link
Collaborator

gdesmott commented Nov 3, 2025

Iterator - Metric - Read Dense/C time: [20.131 ms 21.760 ms 23.450 ms]
Iterator - Metric - Read Dense/Rust time: [11.689 ms 11.726 ms 11.771 ms]

Iterator - Metric - Read Sparse/C time: [1.0607 ms 1.0628 ms 1.0664 ms]
Iterator - Metric - Read Sparse/Rust time: [11.645 ms 11.652 ms 11.660 ms]

Iterator - Metric - SkipTo Dense/C time: [137.25 µs 138.99 µs 142.01 µs]
Iterator - Metric - SkipTo Dense/Rust time: [224.61 µs 225.13 µs 225.67 µs]

Iterator - Metric - SkipTo Sparse/C time: [5.1269 ms 5.1291 ms 5.1311 ms]
Iterator - Metric - SkipTo Sparse/Rust time: [17.315 ms 17.324 ms 17.334 ms]

The Rust implementation is significantly slower than the C one.

I'm pretty sure it's because of the 2 ffi calls in set_result_metrics (ResultMetrics_Reset_func and array_ensure_append_n_func) which cannot be inlined.

I did some profiling and indeed we see most of the time is spent there.

image image

So I'm afraid there is not much we can do at this point. The best way to solve this would be enable C/Rust LTO (MOD-10751) and/or to port RSYieldableMetric to Rust which requires RSValue to be ported first (MOD-11411).

I'd suggest we merge this for now and open another task reminding us to re-check performance once progress has been made on those other fronts.

@GuyAv46 : what do you think?

@BenGoldberger
Copy link
Collaborator Author

@gdesmott do we know why we need all the C mocks in the test?

@gdesmott
Copy link
Collaborator

gdesmott commented Nov 3, 2025

@gdesmott do we know why we need all the C mocks in the test?

No, but it seems it's not a new problem with coverage, see https://github.com/RediSearch/RediSearch/blob/master/build.sh#L576

I hope we'll find soon a better way to manage C code from Rust tests and benches.

@gdesmott
Copy link
Collaborator

gdesmott commented Nov 3, 2025

I'd suggest we merge this for now and open another task reminding us to re-check performance once progress has been made on those other fronts.

Opened MOD-12235 for this.

gdesmott
gdesmott previously approved these changes Nov 3, 2025
@gdesmott gdesmott enabled auto-merge November 3, 2025 14:52
GuyAv46
GuyAv46 previously approved these changes Nov 3, 2025
Copy link
Collaborator

@GuyAv46 GuyAv46 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STAMPA

@gdesmott gdesmott added this pull request to the merge queue Nov 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 3, 2025
@BenGoldberger BenGoldberger added this pull request to the merge queue Nov 4, 2025
Merged via the queue into master with commit b7ac496 Nov 4, 2025
24 checks passed
@BenGoldberger BenGoldberger deleted the beng-rust-metric-iterator branch November 4, 2025 12:17
@BenGoldberger BenGoldberger changed the title [MOD-10084] Beng-rust-metric-iterator [MOD-10084] port metric iterator to rust Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants