Skip to content

[MOD-8973] Rust trie iterators#5928

Closed
hdoordt wants to merge 21 commits intomasterfrom
rust-trie-iter
Closed

[MOD-8973] Rust trie iterators#5928
hdoordt wants to merge 21 commits intomasterfrom
rust-trie-iter

Conversation

@hdoordt
Copy link
Collaborator

@hdoordt hdoordt commented Apr 14, 2025

To do:

Describe the changes in the pull request

A clear and concise description of what the PR is solving, including:

  1. Current: The current state briefly
  2. Change: What is the change
  3. Outcome: Adding the outcome

Which additional issues this PR fixes

  1. MOD-...
  2. #...

Main objects this PR modified

  1. ...

Mark if applicable

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

@hdoordt hdoordt marked this pull request as draft April 14, 2025 15:21
@RediSearch RediSearch deleted a comment from github-actions bot Apr 14, 2025
Comment on lines +279 to +290
let map = Rc::new(map);
group.bench_function("Rust", |b| {
b.iter_batched(
|| map.clone(),
|map| {
map.lending_iter_prefix(&pattern).for_each(|entry| {
black_box(entry);
});
},
BatchSize::LargeInput,
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let map = Rc::new(map);
group.bench_function("Rust", |b| {
b.iter_batched(
|| map.clone(),
|map| {
map.lending_iter_prefix(&pattern).for_each(|entry| {
black_box(entry);
});
},
BatchSize::LargeInput,
);
});
group.bench_function("Rust", |b| {
b.iter(|| {
map.lending_iter_prefix(&pattern).for_each(|entry| {
black_box(entry);
})
})
});

We can use iter directly ^ whenever the benchmark is immutable, thus avoiding the Rc workaround.

b.iter_batched(
|| map.clone(),
|map| {
let pat: &[u8] = unsafe { std::mem::transmute(&*pattern) };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't as_bytes do the trick here?

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

1 similar comment
@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

1 similar comment
@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

hdoordt added 8 commits April 22, 2025 16:55
Moves the bindings to `redismodule.h` in the newly
created `redis_modules_test`, along with the Redis
allocator shims and a number of utilities. This allows
for reusing them in tests outside of `trie_bencher`.
`TrieMap_Iterate` is implemented by applying different
iterator adaptors to `trie_rs::iter::LendingIter`, based
on the passed iteration mode. `TrieMapIterator_Next` simply
obtains the next value from the iterator, and
`TrieMapIterator_NextContains` and `TrieMapIterator_NextWildcard`
deletage to `TrieMapIterator_Next`.

This commit furthermore adds a number of tests
to validate the correct operation of the triemap
iterator functionality exposed in the `trie_rs::ffi` module.

This commit also removes the global allocator definition
set in `trie_rs`, as it hinders tests and is to be moved to a façade crate.
Add support for backtracking in `wildcard::TokenStream::matches`,
based on the iterate algorithm described by [Dogan Kurt]

[Dogan Kurt]: http://dodobyte.com/wildcard.html
Add proptests for the `wildcard::TokenStream::matches`
method. One generates random patterns and keys,
and validates that the keys match the patterns
if and only if the [reference crate]'s implementation
matches. The second one constructs keys that match
the pattern and validates that they match.

[reference crate]: https://github.com/cloudflare/wildcard/
Implement TriMap_IterateRange, and add a test
Implement TrieMap_RandomValueByPrefix and add a test
@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

1 similar comment
@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

1 similar comment
@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@github-actions
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants