Skip to content

Commit

Permalink
runtime: skip wb call in growslice when unnecessary
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
josharian committed Mar 25, 2019
1 parent 2034fba commit 24f846e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 24f846e

Please sign in to comment.