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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop yielding once all evaluations are started #527

Merged
merged 1 commit into from Jul 8, 2023

Conversation

andrews05
Copy link
Collaborator

This improves upon the previous change in #524. Rather than yielding as long there are tasks available, it keeps of track of how many evaluations have been started and only yields when there are still evaluations to be done.

This is important if there is a large queue of other (non-evaluation) tasks available. It doesn't guarantee that it won't pick up a non-evaluation task but it does make it highly unlikely and effectively eliminates any problems that may arise from that happening too often. (@Pr0methean has yet to confirm whether this fixes his stack overflow problem in #517 but I'm pretty confident that it does)

@shssoichiro Note my other PRs are also ready for review 馃檪

@cuviper
Copy link
Contributor

cuviper commented Jul 3, 2023

I commented on rayon before I had seen your change: rayon-rs/rayon#1064 (comment)

My idea was to use try_recv until disconnected. That's not much different than what you're doing, except it would let you use the channel's internal connection count instead of adding a separate counter yourself.

@andrews05
Copy link
Collaborator Author

@cuviper Thanks for the suggestion! I tried this out just now - the difference is the separate counter here allows it to stop yielding as soon the evaluations have all been started, whereas checking try_recv will keep yielding until the evaluations are all finished, meaning it will most likely pick up some other task while waiting. It probably wouldn't be a problem (since it would still be a major improvement over the previous code), but I think it would be preferable to avoid that as much as possible.

@cuviper
Copy link
Contributor

cuviper commented Jul 3, 2023

Makes sense! Although I will point out that your commit and PR subject say "done", not "started". :)
(... and then you did say "started" in the body.)

@andrews05 andrews05 changed the title Stop yielding once evaluations are done Stop yielding once all evaluations are started Jul 3, 2023
@andrews05
Copy link
Collaborator Author

Ha, good point - changed :)

@Pr0methean
Copy link
Contributor

This fix seems to work so far.

@shssoichiro shssoichiro merged commit 775e718 into shssoichiro:master Jul 8, 2023
11 checks passed
@andrews05 andrews05 deleted the parallel branch July 9, 2023 01:02
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.

None yet

4 participants