Repository navigation
perf(runtime): compute an expression's footprint once per model - #1347
Merged
Merged
Conversation
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This was referenced Oct 21, 2026
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
The 0.11.0 performance record (measured against
v0.10.1) finds every loop row ofinternal/exec/runtimetwo allocations per pass heavier than the release:IntegerArithmeticLoop9 072 → 11 073 allocs/op and 280 → 483 KiB,RationalDecimalLoopandRealDecimalLoopthe same,IntegerArithmeticNestedLoop26.08k → 30.08k,AssignmentLoopStep7 329 → 7 529, andtests/perfActionLoop/for10004 231 → 6 264. Bisected over the pull-request merges to #1136 (transitive order dependence):stmtEngine.iterationcallslower.ExpressionFootprinton the loop's condition on every pass, and the footprint builder'sappendPlacegrows a freshReadsslice each time (pprof: 2 016 of the 2 001 extra allocations). The same per-evaluation rebuild sits onifguards,untilconditions,forcollections, transition guards andsendmessages.What an expression reads is a property of the expression, not of the pass, so the
Modelnow memoizeslower.ExpressionFootprintby(scope, expression)in a plain map like its other memos (names,features), and the seven call sites take it from there.standingOfreads the footprint only, so sharing it is safe.How it was verified
TestExpressionFootprintIsMemoizedPerModel: the memoized footprint equals the lowering's and a repeated request allocates nothing.TestLoopIterationDoesNotRebuildConditionFootprint: a differentialtesting.AllocsPerRunbound — one more pass of theLoopcalc'swhile(runs of 2n and n iterations, per iteration) costs at most 9 allocations. Ondevelopbefore this change it costs 11.00 and the test fails; with it 9.00.d5e2317de(the parent of the feat(runtime): mark values computed from order-dependent ones #1136 merge) in a scratch worktree |developb60a18c20| this branch, allocs/op:IntegerArithmeticLoop9 072 | 11 073 | 9 072;IntegerArithmeticNestedLoop26.08k | 30.08k | 26.08k;RationalDecimalLoop9 071 | 11 072 | 9 072;AssignmentLoopStep7 329 | 7 529 | 7 328; B/opIntegerArithmeticLoop279.9 | 483.3 | 295.7 KiB.NewRootFrame(55) andDerivedReadWriteRead(71) are unchanged by this branch; they moved befored5e2317deand are being attributed separately.go test ./internal/exec/runtime(the one failure without the pilot corpora present,TestPilotProvidePowerRunsUntilItsAccept, passes with them),go build ./...,go vet ./internal/exec/...,gofmt -l .empty,python3 scripts/changelog.py check.Checklist
make testandmake lintpass locally (runtime package and the gates above; the full suite runs in CI)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (none moved)F4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/cf22d7a746814d20b2f0eaf11682fef9
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/cf22d7a746814d20b2f0eaf11682fef9?variant=devin
Requested by: @HuiJun