Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Vec::retain instead of Vec::remove #83

Merged
merged 6 commits into from
Jan 19, 2021

Conversation

Kerollmops
Copy link
Member

@Kerollmops Kerollmops commented Jan 19, 2021

There are many places where we use the Vec::remove method. It can bring a lot of performances issues as every time this function is called, the right part of the Vec (after the removed element) is shifted to the left by one, when a lot of element must be removed, we should always use Vec::retain which is more optimized for this in the sense that it will avoid calling a lot the copy function for when multiple elements must be removed at the same time.

I found that doing this change in the Store::intersect_with method for the Array-Array operation gave me much better performances (7m intersected with 3m and intersected with 4m again), moving from 240ms to 55ms. I am sure that we can optimize the current implementation more.

  • Stores intersections.
  • Stores differences.
  • Stores symmetric differences.

@Kerollmops Kerollmops force-pushed the use-vec-retain-instead-of-remove branch from 926dc1f to 50e9cf7 Compare January 19, 2021 15:19
@Kerollmops
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Jan 19, 2021
@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

try

Build failed:

@Kerollmops
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Jan 19, 2021
@Kerollmops
Copy link
Member Author

bors try

@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

try

Already running a review

@Kerollmops
Copy link
Member Author

bors try

@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

try

Already running a review

@Kerollmops Kerollmops force-pushed the use-vec-retain-instead-of-remove branch from 64897f0 to 7be13bd Compare January 19, 2021 18:23
@Kerollmops
Copy link
Member Author

bors try

@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

try

Already running a review

@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

try

Build failed:

  • ci (stable)

@Kerollmops
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Jan 19, 2021
@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

try

Build succeeded:

@Kerollmops
Copy link
Member Author

bors r+

@Kerollmops Kerollmops marked this pull request as ready for review January 19, 2021 19:15
@bors
Copy link
Contributor

bors bot commented Jan 19, 2021

Build succeeded:

@bors bors bot merged commit e8ef6b8 into master Jan 19, 2021
@bors bors bot deleted the use-vec-retain-instead-of-remove branch January 19, 2021 19:19
bors bot added a commit that referenced this pull request Jan 23, 2021
85: Replace Vec remove by a retain_mut function in Container operations r=Kerollmops a=Kerollmops

We introduce a `retain_mut` function that allows us to mutate the iterated element. There already were [a discussion about this `Vec::retain` parameter restriction](rust-lang/rust#25477).

Using the `retain` algorithm is much better when multiple stores must be removed in one batch, same as in #83.

Co-authored-by: Clément Renault <[email protected]>
not-jan pushed a commit to not-jan/roaring-rs that referenced this pull request Aug 31, 2022
83: Use Vec::retain instead of Vec::remove r=Kerollmops a=Kerollmops

There are many places where we use [the `Vec::remove` method](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.remove). It can bring a lot of performances issues as every time this function is called, the right part of the Vec (after the removed element) is shifted to the left by one, when a lot of element must be removed, we should always use [`Vec::retain`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain) which is more optimized for this in the sense that it will avoid calling a lot the copy function for when multiple elements must be removed at the same time.

I found that doing this change in the `Store::intersect_with` method for the Array-Array operation gave me much better performances (7m intersected with 3m and intersected with 4m again), moving from 240ms to 55ms. I am sure that we can optimize the current implementation more.

- [x] Stores intersections.
- [x] Stores differences.
- [ ] Stores symmetric differences.

Co-authored-by: Clément Renault <[email protected]>
Co-authored-by: Kerollmops <[email protected]>
not-jan pushed a commit to not-jan/roaring-rs that referenced this pull request Aug 31, 2022
85: Replace Vec remove by a retain_mut function in Container operations r=Kerollmops a=Kerollmops

We introduce a `retain_mut` function that allows us to mutate the iterated element. There already were [a discussion about this `Vec::retain` parameter restriction](rust-lang/rust#25477).

Using the `retain` algorithm is much better when multiple stores must be removed in one batch, same as in RoaringBitmap#83.

Co-authored-by: Clément Renault <[email protected]>
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