Skip to content

runtime: consider using batched shuffle in selectgo #68933

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

Open
josharian opened this issue Aug 18, 2024 · 5 comments
Open

runtime: consider using batched shuffle in selectgo #68933

josharian opened this issue Aug 18, 2024 · 5 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@josharian
Copy link
Contributor

josharian commented Aug 18, 2024

This is a minor optimization opportunity. runtime.selectgo typically does a shuffle of a fairly small number of channels. https://lemire.me/blog/2024/08/17/faster-random-integer-generation-with-batching/ introduces an optimization for such shuffles. It might be worth incorporating the technique into selectgo. (math/rand/v2 is probably not possible due to backwards compat.)

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 18, 2024
@cherrymui cherrymui added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance labels Aug 19, 2024
@cherrymui cherrymui added this to the Backlog milestone Aug 19, 2024
@mknyszek
Copy link
Contributor

In triage, I don't think we have the bandwidth to look into this now, but patches welcome. :)

@lemire
Copy link

lemire commented Sep 9, 2024

@josharian Do you know how we might benchmark this?

@josharian
Copy link
Contributor Author

Something like BenchmarkSelectSync* in package runtime. Maybe add some benchmarks with more cases.

@thatnealpatel thatnealpatel self-assigned this Jan 14, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/642775 mentions this issue: runtime: implement faster random number generation for select statements

@lemire
Copy link

lemire commented Apr 6, 2025

As a reference...

Daniel Lemire, "Faster shuffling in Go with batching," in Daniel Lemire's blog, April 6, 2025, https://lemire.me/blog/2025/04/06/faster-shuffling-in-go-with-batching/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
Development

No branches or pull requests

6 participants