/ go Public
cmd/compile: rewrite sequences of mutex calls #41253
Issues related to the Go compiler and/or runtime.
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Just a random idea that may be worth considering. It should be safe (at least on amd64) for the compiler to rewrite sequences of
Especially the latter is used in low-priority long-running operations holding a mutex to yield to higher-priority operations, like:
(that ideally should instead be written as follows, but that would require a much smarter compiler)
The benefit being that, in the no-contention case, we would avoid two RMW atomic ops and replace it with a single atomic load from a location that is almost certainly already in cache, plus a predictable jump (in the contention case the extra load+jump would be overshadowed by the rest of the mutex machinery, so it shouldn't matter anyway). I haven't benchmarked this yet: I can do it if we're interested in adding this.
A (imperfect) search on the the GH dataset on BQ shows the following number of occurrences:
The text was updated successfully, but these errors were encountered: