Permalink
Browse files

runtime: avoid division in gc

Replace int division with (cheaper) byte division in heapBitsSetType.
Provides noticeable speed-up:

GrowSlicePtr-6   181ns ± 3%   169ns ± 3%  -6.85%  (p=0.000 n=10+10)

Change-Id: I4064bb72e8e692023783b8f58d19491844c39382
Reviewed-on: https://go-review.googlesource.com/42290
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
  • Loading branch information...
TocarIP authored and bradfitz committed May 1, 2017
1 parent d263e85 commit a4ee95c805fb77e594603bcd62d7858dc9e853ab
Showing with 3 additions and 1 deletion.
  1. +3 −1 src/runtime/mbitmap.go
View
@@ -1047,7 +1047,9 @@ func heapBitsSetType(x, size, dataSize uintptr, typ *_type) {
endnb += endnb
}
// Truncate to a multiple of original ptrmask.
endnb = maxBits / nb * nb
// Because nb+nb <= maxBits, nb fits in a byte.
// Byte division is cheaper than uintptr division.
endnb = uintptr(maxBits/byte(nb)) * nb
pbits &= 1<<endnb - 1
b = pbits
nb = endnb

0 comments on commit a4ee95c

Please sign in to comment.