Commit 621aa713 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: avoid allocation in Nodes.Set in common case

When building make.bash, calling Nodes.Set(s) where len(s) == 0 occurs
4738678 times vs 1465415 calls where len(s) > 0; i.e., it is over 3x
more common to set Nodes.slice to nil rather than to s.

Make a copy of slice (header) and take address of that copy instead
to avoid allocating the argument slice on the heap always even when
not needed.

Saves 4738678 slice header allocations and slice header value copies.

Change-Id: I88e8e919ea9868ceb2df46173d187af4109bd947
Reviewed-on: https://go-review.googlesource.com/21241Reviewed-by: default avatarAlan Donovan <adonovan@google.com>
parent 390d1ce6
......@@ -415,7 +415,11 @@ func (n *Nodes) Set(s []*Node) {
if len(s) == 0 {
n.slice = nil
} else {
n.slice = &s
// Copy s and take address of t rather than s to avoid
// allocation in the case where len(s) == 0 (which is
// over 3x more common, dynamically, for make.bash).
t := s
n.slice = &t
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment