Repository navigation
perf(runtime): compute a statement's order and stamped footprint once per model - #1355
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)".
|
Co-Authored-By: jason.han <hanhuijun@gmail.com>
… per model Co-Authored-By: jason.han <hanhuijun@gmail.com>
4 of 6 tasks
… statement kind keyed Co-Authored-By: jason.han <hanhuijun@gmail.com>
4 of 6 tasks
6 tasks done
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 against v0.10.1 (#1337) attributes the growth of every executor statement row —
ActionLoop+48 % allocations at a thousand passes,ActionChain/chain1000+22 % allocations and +72 % time,StateLoopandExecuteState+12 %,ExecuteAction+15 %, the bytes ofMaterializePlainAttributesandSetFeatureValueNoDependents— to #1136 (transitive order dependence), by first-parent bisection with exact allocation counts. Three per-execution costs on the statement path cause it:actionStmtHost.statementFootprintstamps the statement's footprint with the performance's own places sopropagateMarksrecords the write as the performance's;placesOfcloned the read and write place slices on every call, two allocations per executed assignment. The stamped footprint depends only on the statement and the performed node, so it is now memoized per model (Model.stamped), and a footprint with nothing to stamp is used as it is.performances.statementOrdermemoizedlower.BodyStatementOrderon theperformancesvalue, which is one perActionExecutor— so a chain of a thousand actions rebuilt every body's order on every run, and a state's entry or do behavior, whose host makes a freshperformancesper entry (behaviorHost), rebuilt its order on every entry, allocating a syntheticActionGraphto do so. The memo is nowModel.statementOrder, keyed by the body's node, its first statement's syntax (lower.StatementNode, exported for it) and its length — one list per model has those, and lowered statement slices are per executor, so their addresses could not key it.StateExecutor.taking/Context.underControl), is the other half of the state rows and is fixed separately in its own pull request, so each change stays one mechanism.No behaviour changes: the orders and footprints computed are the same values, computed once.
How it was verified
Failing-before differential tests in
internal/exec/runtime/statement_footprint_stamp_test.go(testing.AllocsPerRun, the cost of one more unit as the difference between 2n and n units; develop → this branch, allocations exact):A/B over six interleaved rounds (
go test -bench -count 1per round,nice; pre-#1136 d5e2317 | develop a662c2b | this branch). Allocations are exact; the machine was loaded (builds and tests ran beside it), so times carry ±100–500 % spreads and only the allocation and byte columns are stated:ActionLoop/for10ActionLoop/for100ActionLoop/for1000ActionChain/chain10ActionChain/chain100ActionChain/chain1000ExecuteActionExecuteActionFreshContextExecuteStateStateLoop/count50StateLoop/count500StateLoop/count5000MaterializePlainAttributesSetFeatureValueNoDependentsThe action rows return to the pre-#1136 count (+0.1–0.8 %). The state rows recover half; the other half is the two closures per transition taken, fixed in #1356 (both together: 120.00 allocations per state event in the differential test, against 133.50 on develop).
ExecuteActionFreshContextkeeps what a fresh context's first run computes for its model (the memos are per model, and that benchmark makes a model per operation).MaterializePlainAttributesandSetFeatureValueNoDependentsmove in bytes only and are not this cost; the record (#1337) carries them as #1136's.ActionChain/chain1000time: 17.4 | 33.1 | 18.6 ms (p=0.13 against pre-#1136).Gates:
gofmt -l .empty,go vet ./...,go build ./...,go test ./internal/exec/... ./internal/ir/lower/... ./tests/hygiene,python3 scripts/changelog.py check.Checklist
make testandmake lintpass locally (the packages above; the full suite runs in CI)changes/unreleased/stamp-statement-footprint-once.fixed.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