cmd/internal/gc: separate func-only Node fields
Nodes dominate gc's memory usage, but many fields are only used
for a subset of kinds of nodes. This change pulls out fields
used only for func-like Nodes. This reduces the size of the
Node struct on a 64-bit machine from 504 bytes to 416 bytes (-17%).
Compiling the runtime, 1.5% of nodes have a non-nil Func.
In html/template, 2.7% of nodes have a non-nil Func.
This change introduces an extra alloc and associated GC overhead
when Func is non-nil. However, when Func is nil, as it almost
always is, it spares the garbage collector scanning some Node fields.
Empirically, this change appears to be roughly neutral with regard to GC.
To keep the diff readable, this CL uses an embedded Func field.
A subsequent CL will unembed the field.
Passes toolstash -cmp.
Change-Id: Ide86aa954b097fb8e6154f0811d3691497477004
Reviewed-on: https://go-review.googlesource.com/7360
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/src/cmd/internal/gc/dcl.go b/src/cmd/internal/gc/dcl.go
index 64be3e7..4e298a3 100644
--- a/src/cmd/internal/gc/dcl.go
+++ b/src/cmd/internal/gc/dcl.go
@@ -373,6 +373,14 @@
return n
}
+// newfuncname generates a new name node for a function or method.
+// TODO(rsc): Use an ODCLFUNC node instead. See comment in CL 7360.
+func newfuncname(s *Sym) *Node {
+ n := newname(s)
+ n.Func = new(Func)
+ return n
+}
+
/*
* this generates a new name node for a name
* being declared.
@@ -542,6 +550,7 @@
Yyerror("methods must have a unique non-blank name")
}
+ n.Func = new(Func)
dclcontext = PPARAM
markdcl()
Funcdepth++
@@ -1312,7 +1321,7 @@
}
if t.Sym == nil || isblank(n) {
- return newname(n.Sym)
+ return newfuncname(n.Sym)
}
var p string
@@ -1323,9 +1332,9 @@
}
if exportname(t.Sym.Name) {
- n = newname(Lookup(p))
+ n = newfuncname(Lookup(p))
} else {
- n = newname(Pkglookup(p, t.Sym.Pkg))
+ n = newfuncname(Pkglookup(p, t.Sym.Pkg))
}
return n
@@ -1476,7 +1485,7 @@
s1 := Pkglookup(s.Name+"·f", s.Pkg)
if s1.Def == nil {
- s1.Def = newname(s1)
+ s1.Def = newfuncname(s1)
s1.Def.Shortname = newname(s)
funcsyms = list(funcsyms, s1.Def)
}