After allocating a Node that needs a Name, Param, and/or Func field,
we never clear that field, so we can reduce GC overhead slightly by
allocating them together with the owner Node.
name old time/op new time/op delta
Template 325ms ± 7% 325ms ± 7% ~ (p=0.910 n=29+30)
Unicode 177ms ±12% 173ms ±11% ~ (p=0.110 n=29+30)
GoTypes 1.06s ± 7% 1.05s ± 5% -1.22% (p=0.027 n=30+30)
Compiler 4.48s ± 3% 4.47s ± 3% ~ (p=0.423 n=30+30)
name old user-ns/op new user-ns/op delta
Template 476M ±22% 467M ±14% ~ (p=0.310 n=29+30)
Unicode 298M ±22% 294M ±25% ~ (p=0.335 n=30+30)
GoTypes 1.54G ± 9% 1.48G ± 9% -4.06% (p=0.000 n=30+30)
Compiler 6.26G ± 6% 6.14G ± 6% -1.90% (p=0.004 n=30+30)
name old alloc/op new alloc/op delta
Template 40.9MB ± 0% 41.1MB ± 0% +0.53% (p=0.000 n=30+30)
Unicode 30.9MB ± 0% 31.0MB ± 0% +0.16% (p=0.000 n=30+30)
GoTypes 122MB ± 0% 123MB ± 0% +0.37% (p=0.000 n=30+30)
Compiler 477MB ± 0% 479MB ± 0% +0.37% (p=0.000 n=30+29)
name old allocs/op new allocs/op delta
Template 400k ± 1% 376k ± 1% -5.96% (p=0.000 n=30+30)
Unicode 330k ± 1% 325k ± 1% -1.48% (p=0.000 n=30+30)
GoTypes 1.22M ± 0% 1.16M ± 0% -4.38% (p=0.000 n=30+30)
Compiler 4.35M ± 0% 4.13M ± 0% -5.08% (p=0.000 n=30+29)
Change-Id: I9bdc7d9223bb32f785df71810564e82d9a76d109
Reviewed-on: https://go-review.googlesource.com/36022
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
}
func nod(op Op, nleft *Node, nright *Node) *Node {
- n := new(Node)
- n.Op = op
- n.Left = nleft
- n.Right = nright
- n.Pos = lineno
- n.Xoffset = BADWIDTH
- n.Orig = n
+ var n *Node
switch op {
case OCLOSURE, ODCLFUNC:
- n.Func = new(Func)
+ var x struct {
+ Node
+ Func
+ }
+ n = &x.Node
+ n.Func = &x.Func
n.Func.IsHiddenClosure = Curfn != nil
case ONAME:
- n.Name = new(Name)
- n.Name.Param = new(Param)
+ var x struct {
+ Node
+ Name
+ Param
+ }
+ n = &x.Node
+ n.Name = &x.Name
+ n.Name.Param = &x.Param
case OLABEL, OPACK:
- n.Name = new(Name)
+ var x struct {
+ Node
+ Name
+ }
+ n = &x.Node
+ n.Name = &x.Name
+ default:
+ n = new(Node)
}
+ n.Op = op
+ n.Left = nleft
+ n.Right = nright
+ n.Pos = lineno
+ n.Xoffset = BADWIDTH
+ n.Orig = n
if n.Name != nil {
n.Name.Curfn = Curfn
}