]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid division in gc
authorIlya Tocar <ilya.tocar@intel.com>
Mon, 1 May 2017 19:27:36 +0000 (14:27 -0500)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 5 Jun 2017 16:32:02 +0000 (16:32 +0000)
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>
src/runtime/mbitmap.go

index 82bfe84267f91f6a03e2cafbbb27e17dd4045e8e..2a9f1b83e591336b05ca16d85b85bcad90c036e6 100644 (file)
@@ -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