golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.84k stars 17.51k forks source link

runtime: consider using batched shuffle in selectgo #68933

Open josharian opened 3 weeks ago

josharian commented 3 weeks ago

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.)

mknyszek commented 3 weeks ago

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

lemire commented 3 days ago

@josharian Do you know how we might benchmark this?

josharian commented 3 days ago

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