aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2019-03-22 14:51:33 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2019-03-25 17:11:46 +0000
commit24f846e21240f6d6ab2ca23fe319230b7d7f8168 (patch)
treeec155f1507cfc0a537c56a603e6225e34d785edc /src/runtime/slice.go
parent2034fbab5b1d11bc59cb476bc3f49ee1b344839d (diff)
downloadgo-24f846e21240f6d6ab2ca23fe319230b7d7f8168.tar.gz
go-24f846e21240f6d6ab2ca23fe319230b7d7f8168.zip
runtime: skip wb call in growslice when unnecessary
Instrumenting make.bash reveals that almost half (49.54%) of the >16 million calls to growslice for pointer-containing slices are growing from an empty to a non-empty slice. In that case, there is no need to call the write barrier, which does some work before discovering that no pointers need shading. Change-Id: Ide741468d8dee7ad43ea0bfbea6ccdf680030a0f Reviewed-on: https://go-review.googlesource.com/c/go/+/168959 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index 2309b1a615..dca41ff8cd 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -179,7 +179,7 @@ func growslice(et *_type, old slice, cap int) slice {
} else {
// Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory.
p = mallocgc(capmem, et, true)
- if writeBarrier.enabled {
+ if lenmem > 0 && writeBarrier.enabled {
// Only shade the pointers in old.array since we know the destination slice p
// only contains nil pointers because it has been cleared during alloc.
bulkBarrierPreWriteSrcOnly(uintptr(p), uintptr(old.array), lenmem)