]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: evaluate map initializers incrementally
authorKeith Randall <khr@google.com>
Mon, 29 Apr 2019 19:19:30 +0000 (12:19 -0700)
committerKeith Randall <khr@golang.org>
Mon, 29 Apr 2019 23:45:15 +0000 (23:45 +0000)
commitee59c06acb1cd0a119667fce57988801d3fdde4f
treed980f0d708fe03f3d52daafd7648627d51c41b01
parent998cc2a1c5cad0e928f0ac07f69af36123192460
cmd/compile: evaluate map initializers incrementally

For the code:

m := map[int]int {
  a(): b(),
  c(): d(),
  e(): f(),
}

We used to do:

t1 := a()
t2 := b()
t3 := c()
t4 := d()
t5 := e()
t6 := f()
m := map[int]int{}
m[t1] = t2
m[t3] = t4
m[t5] = t6

After this CL we do:

m := map[int]int{}
t1 := a()
t2 := b()
m[t1] = t2
t3 := c()
t4 := d()
m[t3] = t4
t5 := e()
t6 := f()
m[t5] = t6

Ordering the initialization this way limits the lifetime of the
temporaries involved.  In particular, for large maps the number of
simultaneously live temporaries goes from ~2*len(m) to ~2. This change
makes the compiler (regalloc, mostly) a lot happier. The compiler runs
faster and uses a lot less memory.

For #26546, changes compile time of a big map from 8 sec to 0.5 sec.

Fixes #26552

Update #26546

Change-Id: Ib7d202dead3feaf493a464779fd9611c63fcc25f
Reviewed-on: https://go-review.googlesource.com/c/go/+/174417
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/sinit.go