Repository navigation
perf(runtime): allocate less to bracket a feature read - #2388
Merged
Merged
Conversation
Reading a feature value brackets the read in a run. The bracket allocated three closures where one does, a calc-usage table most runs never write, and spelled out the owner path at every owner on the way up although only an owner declaring bindings reads it. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
There was a problem hiding this comment.
Devin Review found 1 finding. Devin automatically fixed it.
Fixed by Devin (1)
- Run-state comment exceeds two-line limit — Comment shortened to two lines.
This was referenced Nov 19, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Reading a feature value brackets the read in a run of its own, and that bracket allocated more than it needs. Since the instance graph of a gRPC answer is walked with
Context.Traverseand then serialized, every feature value of the graph is read twice, so the fixed cost per read shows up directly inBenchmarkGRPCVerifyConstraint: with #2378, #2379 and #2380 applied it still allocates 26% more than v0.12.1.Three changes, none of which alters what a read does:
beginRunreturns one closure instead of composing three (nestRun's,syncBoundary's and its own).runState.calcUsageRunsis made when a run first evaluates a calc usage rather than for every run; most runs never write it.resolveBindingsspells out the owner feature path only at an owner that declares bindings, the one place the path is read, instead of concatenating at every owner on the way up.Against v0.12.1, with the three pull requests above merged in,
GRPCVerifyConstraintgoes from +26.45% to +3.07% allocs/op and from +27.69% to +16.66% B/op;Instantiatefrom +2.47% to +1.11% allocs/op.Not addressed here: the time of
GRPCVerifyConstraintandInstantiateand the bytes ofInstantiatedo not move measurably. What remains there is the second read of each feature value thatTraverseadds to the instance graph, and per-type work done the first time a type is instantiated (lowering a state machine's expressions into itsExprTable, thereachingSubsettersindex).How it was verified
go build ./...,go vet ./...andgofmt -l .are clean.go test -count=1 ./internal/exec/... ./internal/frontend/... ./tests/grpc/... ./tests/perf/...passes, apart from the two training-corpus tests ofinternal/exec/solve, which did not find the corpus in the worktree they ran in.TestReleaseInsideAnotherRunEndsThePausedRunsOwnnow makes the table it writes to, since a fresh run no longer carries one.Benchmarks:
tests/perf, six interleaved rounds, on develop with #2378, #2379 and #2380 merged, before and after this change:The same, v0.12.1 against this change:
Checklist
make testandmake lintpass locally — not run in full; the packages above were run insteadchanges/unreleased/<slug>.<section>.md— none: no behavior a user reads about changesmake docs-countsrun if a gate count moved (none moved)F4,K5) in the body, docs, or changelog🟢 Devin Review found nothing to fix · View findings · Follow Devin's work