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>
Showing
Please register or sign in to comment