Merged
Conversation
generall
commented
Nov 13, 2025
Member
Author
There was a problem hiding this comment.
main changes in this file
coszio
approved these changes
Nov 13, 2025
6 tasks
6943774 to
aab2245
Compare
timvisee
approved these changes
Nov 14, 2025
Comment on lines
+21
to
+25
| // AI says, that if atomic is not updated frequently, | ||
| // it is cheap enough to check it on every iteration. | ||
| if self.is_stopped.load(Ordering::Relaxed) { | ||
| return None; | ||
| } |
Member
There was a problem hiding this comment.
So here's a stupid idea:
I'm curious if we could just ignore atomics here and concurrently set the boolean.
It'd be cheaper by not using atomic operations, at the cost of potentially 'recognizing' the changed flag a bit later due to local caches.
Member
There was a problem hiding this comment.
Turns out the non-atomic variant is exactly the same for reads on x86_64 and ARM:
https://rust.godbolt.org/z/oe4f17xEo
Thanks @xzfc !
| fn next(&mut self) -> Option<Self::Item> { | ||
| // AI says, that if atomic is not updated frequently, | ||
| // it is cheap enough to check it on every iteration. | ||
| if self.is_stopped.load(Ordering::Relaxed) { |
Member
There was a problem hiding this comment.
I also checked the unlikely and cold_path intrinsic just for fun, but they aren't stable yet :(
Member
|
Thanks for the benchmarks supporting the change 👍 |
timvisee
added a commit
that referenced
this pull request
Nov 14, 2025
* add stopflag check into query_points of payload index * propagate stopflag more * fmt * bench: compare better against no atomic * use stoppable iter with IteratorExt * clippy * Add cancelled error helper --------- Co-authored-by: Luis Cossío <luis.cossio@outlook.com> Co-authored-by: timvisee <tim@visee.me>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

iter_filtered_pointsunder some special conditions could consume significant resources and didn't respect stopflag in all cases.Now it does.
I went ahead with another implementation of stopable iterator, because it is easier and apparently also slightly faster (i did benchmark).
I tried to remove newly introduced double checking where I spotted it.
Also we want to check stopflag right after starting search, cause it could have become outdated while waiting in runtime queue.