golang / go

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

cmd/compile: recognize case <-time.After(x) #8895

Open dvyukov opened 10 years ago

dvyukov commented 10 years ago
Compiler can recognize the common:
   case <-time.After(x):
construct and lower it into:
   runtime.selectrecvafter(x)
Runtime can handle this case much more efficiently: no need to create Timer, chan and
arm timers; it just needs to do a timed park of the goroutine until x. As a bonus, the
timer does not leak.
rsc commented 10 years ago

Comment 1:

This may not be necessary depending on what we do or don't do for issue #8898.

Status changed to Accepted.

dvyukov commented 10 years ago

Comment 2:

I agree that this is related to issue #8898, and 8898 will somewhat alleviate benefit
from this optimization.
But this is still somewhat orthogonal thing, as in this case we don't even allocate nor
generate garbage.
bradfitz commented 9 years ago

Comments about this bug are in https://go-review.googlesource.com/#/c/8356/

dvyukov commented 9 years ago

Here is implementation of the optimization: https://go-review.googlesource.com/5032