8000 go/ir: avoid repeated operand scans by Automaat · Pull Request #1747 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

go/ir: avoid repeated operand scans - #1747

Open
Automaat wants to merge 2 commits into
dominikh:masterfrom
Automaat:perf/ir-composite-upstream
Open

Automaat wants to merge 2 commits into
dominikh:masterfrom
Automaat:perf/ir-composite-upstream

Conversation

@Automaat
@Automaat 8000 Automaat commented Sep 17, 2026
Copy link
Copy Markdown

When a value appears multiple times in one CompositeValue, its referrer list contains that instruction once per operand. replaceAll previously rescanned every operand for every duplicate referrer, making replacement quadratic in the number of repeated operands.

Group adjacent occurrences of the same instruction and scan its operands once while preserving duplicate referrers on the replacement value. Add a focused correctness test and benchmark.

Hosted benchmark medians (2 CPU, 1 GiB container):

operands before after
16 1.25 µs 226 ns
64 16.0 µs 748 ns
256 247 µs 2.98 µs
1024 3.88 ms 11.4 µs

The 1024-operand case also drops from 12 allocations to 1.

Validation: full Linux, macOS, and Windows matrix on Go 1.26 and Go 1.27rc1, including go test, go vet, and Staticcheck.

Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0