Skip to content

Commit 40f0359

Browse files
committed
runtime: avoid a bit of unneeded work when MemProfileRate==1
Change-Id: I1dc355bcaeb0e5fb06a7fddc4cf5db596d22e0b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/236148 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Emmanuel Odeke <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent db8142f commit 40f0359

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/runtime/malloc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,13 @@ func profilealloc(mp *m, x unsafe.Pointer, size uintptr) {
12211221
// distribution (exp(MemProfileRate)), so the best return value is a random
12221222
// number taken from an exponential distribution whose mean is MemProfileRate.
12231223
func nextSample() uintptr {
1224+
if MemProfileRate == 1 {
1225+
// Callers assign our return value to
1226+
// mcache.next_sample, but next_sample is not used
1227+
// when the rate is 1. So avoid the math below and
1228+
// just return something.
1229+
return 0
1230+
}
12241231
if GOOS == "plan9" {
12251232
// Plan 9 doesn't support floating point in note handler.
12261233
if g := getg(); g == g.m.gsignal {

0 commit comments

Comments
 (0)