Skip to content

[MOD-10235] Polish varint implementation#6346

Merged
LukeMathWalker merged 13 commits intomasterfrom
clean-up-varint
Jun 25, 2025
Merged

[MOD-10235] Polish varint implementation#6346
LukeMathWalker merged 13 commits intomasterfrom
clean-up-varint

Conversation

@LukeMathWalker
Copy link
Collaborator

@LukeMathWalker LukeMathWalker commented Jun 18, 2025

Describe the changes in the pull request

This PR refactors the Rust varint implementation. There are no functional changes.
In particular:

  • We use a trait-based design, with macros to avoid code duplication.
  • We remove the direct dependency on FieldMask, and therefore on the ffi crate, by providing an encoding/decoding implementation for both u64 and u128. We can thus stop mirroring in the varint test suite the platform-specific knobs that are used, on the C side, to pick the correct size of FieldMask.
  • More extensive documentation all around.
  • More test cases, including errors and property-based tests. We now have 100% test coverage for varint encoding/decoding.
  • Rename encode_decode to varint, since we want to have small self-contained crates to minimize compile times. The existing varint crate is renamed to varint_ffi.

Benchmarks

Benchmarks have been refactored to measure performance based on the expected encoded size, rather than grouping everything together.
You can compare performance before/after the refactoring by executing benches for the first commit on this branch and then re-running them for the latest commit on this branch. No significant changes were measured on my local machine.

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

@LukeMathWalker LukeMathWalker changed the base branch from master to drop-c-varint June 18, 2025 13:01
@LukeMathWalker LukeMathWalker requested a review from chesedo June 18, 2025 13:07
Copy link
Collaborator

@chesedo chesedo left a comment

Choose a reason for hiding this comment

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

Just small nit picky stuff

chesedo
chesedo previously approved these changes Jun 19, 2025
Base automatically changed from drop-c-varint to master June 24, 2025 15:06
@LukeMathWalker LukeMathWalker dismissed chesedo’s stale review June 24, 2025 15:06

The base branch was changed.

@LukeMathWalker LukeMathWalker marked this pull request as ready for review June 24, 2025 15:40
@LukeMathWalker LukeMathWalker requested a review from lerman25 June 24, 2025 15:41
@LukeMathWalker LukeMathWalker changed the title Polish varint implementation [MOD-10235] Polish varint implementation Jun 24, 2025
@codecov
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 5 lines in your changes missing coverage. Please review.

Project coverage is 88.76%. Comparing base (428d202) to head (b8ed78e).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...earch_rs/c_entrypoint/varint_ffi/src/field_mask.rs 0.00% 2 Missing ⚠️
...redisearch_rs/c_entrypoint/varint_ffi/src/value.rs 0.00% 2 Missing ⚠️
src/redisearch_rs/varint/src/vector_writer.rs 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6346      +/-   ##
==========================================
+ Coverage   88.72%   88.76%   +0.04%     
==========================================
  Files         251      251              
  Lines       41729    41606     -123     
  Branches     3748     3625     -123     
==========================================
- Hits        37022    36930      -92     
+ Misses       4658     4632      -26     
+ Partials       49       44       -5     
Flag Coverage Δ
flow 81.34% <ø> (-0.15%) ⬇️
unit 46.66% <92.30%> (-0.06%) ⬇️

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.

Copy link
Collaborator

@lerman25 lerman25 left a comment

Choose a reason for hiding this comment

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

Great, few questions


fn benchmark_core_operations(c: &mut Criterion) {
let bencher = VarintBencher::new("Varint".to_owned(), Duration::from_secs(10));
let bencher = VarintBencher::new(Duration::from_secs(5));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the change from 10 to 5 intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, since the bench cases are now smaller we shouldn't need 10 seconds to achieve statistical significance.
I've just triggered a micro-benchmark run in CI to double-check that's the case in the CI environment too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@LukeMathWalker LukeMathWalker requested a review from lerman25 June 25, 2025 09:35
@LukeMathWalker LukeMathWalker added this pull request to the merge queue Jun 25, 2025
Merged via the queue into master with commit a08d223 Jun 25, 2025
22 checks passed
@LukeMathWalker LukeMathWalker deleted the clean-up-varint branch June 25, 2025 13:06
GuyAv46 added a commit that referenced this pull request Jul 20, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 22, 2025
* Revert "[MOD-10235] Polish varint implementation (#6346)"

This reverts commit a08d223.

* change runner

* Revert "[MOD-9403] Remove stale varint target (#6372)"

This reverts commit f3aefd2.

* Revert "MOD-9403: Replace varint.* with the Rust implementation (#6308)"

This reverts commit 428d202.
@LukeMathWalker LukeMathWalker restored the clean-up-varint branch February 6, 2026 09:22
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.

3 participants