From a4ee95c805fb77e594603bcd62d7858dc9e853ab Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Mon, 1 May 2017 14:27:36 -0500 Subject: [PATCH] runtime: avoid division in gc MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- src/runtime/mbitmap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go index 82bfe84267..2a9f1b83e5 100644 --- a/src/runtime/mbitmap.go +++ b/src/runtime/mbitmap.go @@ -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<