Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4ee95c

Browse files
TocarIPbradfitz
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent d263e85 commit a4ee95c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/runtime/mbitmap.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,9 @@ func heapBitsSetType(x, size, dataSize uintptr, typ *_type) {
10471047
endnb += endnb
10481048
}
10491049
// Truncate to a multiple of original ptrmask.
1050-
endnb = maxBits / nb * nb
1050+
// Because nb+nb <= maxBits, nb fits in a byte.
1051+
// Byte division is cheaper than uintptr division.
1052+
endnb = uintptr(maxBits/byte(nb)) * nb
10511053
pbits &= 1<<endnb - 1
10521054
b = pbits
10531055
nb = endnb

0 commit comments

Comments
 (0)