]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/escape: avoid reading ir.Node during inner loop of walkOne
authorthepudds <thepudds1460@gmail.com>
Wed, 12 Mar 2025 18:45:17 +0000 (14:45 -0400)
committerKeith Randall <khr@golang.org>
Mon, 21 Apr 2025 22:44:05 +0000 (15:44 -0700)
commit04a9b16f3d69aa66f3aaab44dcd322e4a02a82aa
treedad18d03508fbd866c60d8f52be227944540b109
parentc0245b31fb157590b69245f7dff27f0605b73138
cmd/compile/internal/escape: avoid reading ir.Node during inner loop of walkOne

Broadly speaking, escape analysis has two main phases. First, it
traverses the AST while building a data-flow graph of locations and
edges. Second, during "solve", it repeatedly walks the data-flow graph
while carefully propagating information about each location, including
whether a location's address reaches the heap.

Once escape analysis is in the solve phase and repeatedly walking the
data-flow graph, almost all the information it needs is within the
location graph, with a notable exception being the ir.Class of an
ir.Name, which currently must be checked by following a pointer from
the location to its ir.Node.

For typical graphs, that does not matter much, but if the graph becomes
large enough, cache misses in the inner solve loop start to matter more,
and the class is checked many times in the inner loop.

We therefore store the class information on the location in the graph
to reduce how much memory we need to load in the inner loop.

The package github.com/microsoft/typescript-go/internal/checker
has many locations, and compilation currently spends most of its time
in escape analysis.

This CL gives roughly a 30% speedup for wall clock compilation time
for the checker package:

  go1.24.0:      91.79s
  this CL:       64.98s

Linux perf shows a healthy reduction for example in l2_request.miss and
dTLB-load-misses on an amd64 test VM.

We could tweak things a bit more, though initial review feedback
has suggested it would be good to get this in as it stands.

Subsequent CLs in this stack give larger improvements.

Updates #72815

Change-Id: I3117430dff684c99e6da1e0d7763869873379238
Reviewed-on: https://go-review.googlesource.com/c/go/+/657295
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Jake Bailey <jacob.b.bailey@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/escape/graph.go
src/cmd/compile/internal/escape/solve.go