Skip to content

perf(runtime): compute an expression's footprint once per model - #1347

Merged
HuiJun merged 1 commit into
developfrom
perf/memoize-expression-footprints
Oct 21, 2026
Merged

HuiJun merged 1 commit into
developfrom
perf/memoize-expression-footprints

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

What and why

The 0.11.0 performance record (measured against v0.10.1) finds every loop row of internal/exec/runtime two allocations per pass heavier than the release: IntegerArithmeticLoop 9 072 → 11 073 allocs/op and 280 → 483 KiB, RationalDecimalLoop and RealDecimalLoop the same, IntegerArithmeticNestedLoop 26.08k → 30.08k, AssignmentLoopStep 7 329 → 7 529, and tests/perf ActionLoop/for1000 4 231 → 6 264. Bisected over the pull-request merges to #1136 (transitive order dependence): stmtEngine.iteration calls lower.ExpressionFootprint on the loop's condition on every pass, and the footprint builder's appendPlace grows a fresh Reads slice each time (pprof: 2 016 of the 2 001 extra allocations). The same per-evaluation rebuild sits on if guards, until conditions, for collections, transition guards and send messages.

What an expression reads is a property of the expression, not of the pass, so the Model now memoizes lower.ExpressionFootprint by (scope, expression) in a plain map like its other memos (names, features), and the seven call sites take it from there. standingOf reads 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 differential testing.AllocsPerRun bound — one more pass of the Loop calc's while (runs of 2n and n iterations, per iteration) costs at most 9 allocations. On develop before this change it costs 11.00 and the test fails; with it 9.00.
  • Benchmark A/B, six interleaved rounds, pre-regression commit d5e2317de (the parent of the feat(runtime): mark values computed from order-dependent ones #1136 merge) in a scratch worktree | develop b60a18c20 | this branch, allocs/op: IntegerArithmeticLoop 9 072 | 11 073 | 9 072; IntegerArithmeticNestedLoop 26.08k | 30.08k | 26.08k; RationalDecimalLoop 9 071 | 11 072 | 9 072; AssignmentLoopStep 7 329 | 7 529 | 7 328; B/op IntegerArithmeticLoop 279.9 | 483.3 | 295.7 KiB. NewRootFrame (55) and DerivedReadWriteRead (71) are unchanged by this branch; they moved before d5e2317de and 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 test and make lint pass locally (runtime package and the gates above; the full suite runs in CI)
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (no user-facing surface changes)
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (none moved)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Link 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

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review October 21, 2026 08:50
@HuiJun
HuiJun merged commit 2ce843b into develop Oct 21, 2026
50 checks passed
@HuiJun
HuiJun deleted the perf/memoize-expression-footprints branch October 21, 2026 13:56
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