cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets

This reduces compiler memory usage by up to 4% - see compilebench
results below.

name       old time/op     new time/op     delta
Template       245ms ± 4%      241ms ± 2%  -1.88%  (p=0.029 n=10+10)
Unicode        126ms ± 3%      124ms ± 3%    ~     (p=0.105 n=10+10)
GoTypes        805ms ± 2%      813ms ± 3%    ~     (p=0.515 n=8+10)
Compiler       3.95s ± 2%      3.83s ± 1%  -2.96%  (p=0.000 n=9+10)
MakeBash       47.4s ± 4%      46.6s ± 1%  -1.59%  (p=0.028 n=9+10)

name       old user-ns/op  new user-ns/op  delta
Template        324M ± 5%       326M ± 3%    ~     (p=0.935 n=10+10)
Unicode         186M ± 5%       178M ±10%    ~     (p=0.067 n=9+10)
GoTypes        1.08G ± 7%      1.09G ± 4%    ~     (p=0.956 n=10+10)
Compiler       5.34G ± 4%      5.31G ± 1%    ~     (p=0.501 n=10+8)

name       old alloc/op    new alloc/op    delta
Template      41.0MB ± 0%     39.8MB ± 0%  -3.03%  (p=0.000 n=10+10)
Unicode       32.3MB ± 0%     31.0MB ± 0%  -4.13%  (p=0.000 n=10+10)
GoTypes        119MB ± 0%      116MB ± 0%  -2.39%  (p=0.000 n=10+10)
Compiler       499MB ± 0%      487MB ± 0%  -2.48%  (p=0.000 n=10+10)

name       old allocs/op   new allocs/op   delta
Template        380k ± 1%       379k ± 1%    ~     (p=0.436 n=10+10)
Unicode         324k ± 1%       324k ± 0%    ~     (p=0.853 n=10+10)
GoTypes        1.15M ± 0%      1.15M ± 0%    ~     (p=0.481 n=10+10)
Compiler       4.41M ± 0%      4.41M ± 0%  -0.12%  (p=0.007 n=10+10)

name       old text-bytes  new text-bytes  delta
HelloSize       623k ± 0%       623k ± 0%    ~     (all equal)
CmdGoSize      6.64M ± 0%      6.64M ± 0%    ~     (all equal)

name       old data-bytes  new data-bytes  delta
HelloSize      5.81k ± 0%      5.81k ± 0%    ~     (all equal)
CmdGoSize       238k ± 0%       238k ± 0%    ~     (all equal)

name       old bss-bytes   new bss-bytes   delta
HelloSize       134k ± 0%       134k ± 0%    ~     (all equal)
CmdGoSize       152k ± 0%       152k ± 0%    ~     (all equal)

name       old exe-bytes   new exe-bytes   delta
HelloSize       967k ± 0%       967k ± 0%    ~     (all equal)
CmdGoSize      10.2M ± 0%      10.2M ± 0%    ~     (all equal)

Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52
Reviewed-on: https://go-review.googlesource.com/37445
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Aliaksandr Valialkin 2017-02-27 19:56:38 +02:00 committed by Matthew Dempsky
parent fbf4dd91b9
commit ed70f37e73
40 changed files with 610 additions and 524 deletions

View file

@ -702,7 +702,7 @@ func (p *exporter) typ(t *Type) {
p.paramList(sig.Recvs(), inlineable)
p.paramList(sig.Params(), inlineable)
p.paramList(sig.Results(), inlineable)
p.bool(m.Nointerface) // record go:nointerface pragma value (see also #16243)
p.bool(m.Nointerface()) // record go:nointerface pragma value (see also #16243)
var f *Func
if inlineable {
@ -921,7 +921,7 @@ func (p *exporter) paramList(params *Type, numbered bool) {
func (p *exporter) param(q *Field, n int, numbered bool) {
t := q.Type
if q.Isddd {
if q.Isddd() {
// create a fake type to encode ... just for the p.typ call
t = typDDDField(t.Elem())
}
@ -1183,7 +1183,7 @@ func (p *exporter) expr(n *Node) {
// }
// from exprfmt (fmt.go)
for n != nil && n.Implicit && (n.Op == OIND || n.Op == OADDR) {
for n != nil && n.Implicit() && (n.Op == OIND || n.Op == OADDR) {
n = n.Left
}
@ -1256,7 +1256,7 @@ func (p *exporter) expr(n *Node) {
case OPTRLIT:
p.op(OPTRLIT)
p.expr(n.Left)
p.bool(n.Implicit)
p.bool(n.Implicit())
case OSTRUCTLIT:
p.op(OSTRUCTLIT)
@ -1337,8 +1337,8 @@ func (p *exporter) expr(n *Node) {
}
// only append() calls may contain '...' arguments
if op == OAPPEND {
p.bool(n.Isddd)
} else if n.Isddd {
p.bool(n.Isddd())
} else if n.Isddd() {
Fatalf("exporter: unexpected '...' with %s call", opnames[op])
}
@ -1346,7 +1346,7 @@ func (p *exporter) expr(n *Node) {
p.op(OCALL)
p.expr(n.Left)
p.exprList(n.List)
p.bool(n.Isddd)
p.bool(n.Isddd())
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
p.op(op) // must keep separate from OMAKE for importer
@ -1446,7 +1446,7 @@ func (p *exporter) stmt(n *Node) {
p.op(OASOP)
p.int(int(n.Etype))
p.expr(n.Left)
if p.bool(!n.Implicit) {
if p.bool(!n.Implicit()) {
p.expr(n.Right)
}