sasha-s / go-deadlock

Online deadlock detection in go (golang)
Apache License 2.0
1.03k stars 76 forks source link

Reuse timers with sync.Pool #31

Closed millfort closed 6 months ago

millfort commented 6 months ago

Here is the top out for alloc space of heap profile:

      flat  flat%   sum%        cum   cum%
 5845.32MB 42.91% 42.91%  5845.32MB 42.91%  github.com/sasha-s/go-deadlock.callers (inline)
 2851.22MB 20.93% 63.84%  2851.22MB 20.93%  time.NewTimer
 2243.68MB 16.47% 80.32%  8089.69MB 59.39%  github.com/sasha-s/go-deadlock.lock

I haven't figured out how to optimize callers. But for time.NewTimer the change seemed to be quite simple. So I made it.


This change is Reviewable

millfort commented 6 months ago

Reviewed 1 of 2 files at r1, all commit messages. Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @millfort)

deadlock.go line 207 at r1 (raw file):

func releaseTimer(t *time.Timer) {
    if !t.Stop() {
        <-t.C

Would for range t.C {}

be cleaner here?

Stop does not close the channel