Commit a4ee95c8 authored by Ilya Tocar's avatar Ilya Tocar Committed by Brad Fitzpatrick

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: default avatarAustin Clements <austin@google.com>
parent d263e855
...@@ -1047,7 +1047,9 @@ func heapBitsSetType(x, size, dataSize uintptr, typ *_type) { ...@@ -1047,7 +1047,9 @@ func heapBitsSetType(x, size, dataSize uintptr, typ *_type) {
endnb += endnb endnb += endnb
} }
// Truncate to a multiple of original ptrmask. // 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 pbits &= 1<<endnb - 1
b = pbits b = pbits
nb = endnb nb = endnb
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment