Repository navigation
perf(runtime): resolve a feature chain's declarations once per model - #1627
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)".
|
Contributor
Author
|
Gate results for 1a6e62a (Go 1.27.3, same machine):
Overlap: |
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
Gate results for 155b178 (the memo re-keyed by chain node; Go 1.27.3, same machine):
Overlap re-checked on this head: |
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
Since feature values are held by feature rather than by name (#1514), every evaluation of a feature chain notes the declaration each of its segments names (
EvalContext.noteChainMembers) so the reads of its parts resolve to a feature, not a name. Each note allocated twice per evaluation:chainDeclarationsresolved the segments afresh into a new slice, andnoteChainMembersreturned a restore closure. In a calc whose loop assigns four attributes from a calc usage's outputs, the fixed-step integration pattern, that is two allocations per chain read per step — theAssignmentLoopStepregression against v0.11.0 (+9.5 % allocs/op, +8.5 % B/op).The declarations a chain's segments name depend only on the model and on the feature or cast type its base names (
declaredMemberreads the type's shape and the semantic model), so this change:chainDeclarationsper model inModel.chainDeclarations, keyed by the base symbol and the chain expression node (immutable AST). A nested chain such asrig.panel.areais flattened afresh byast.FeatureChainBaseon every evaluation, so the flattened slice is not a stable key — the node is;noteChainMembersreturn the previouschainStaticvalue, restored by the newrestoreChain, instead of a closure —defer ec.restoreChain(ec.noteChainMembers(base, parts))allocates nothing.Measured (
-benchtime 200x, Go 1.27.3 for every column, same machine; sec/op omitted as noisy on this VM):internal/exec/runtimeBenchmarkAssignmentLoopStepddfbb9446The fix recovers 800 of the 815 allocations per call #1514 added; about 50 KB/op of its bytes remain, which come from the other parts of that change (the per-slot feature resolution) and are not addressed here.
How it was verified
TestChainDeclarationsAreResolvedOncePerModel(internal/exec/runtime/chain_declarations_memo_test.go): over a nested chain flattened afresh on every iteration,testing.AllocsPerRunfor 100 vs 50 repeated notes must allocate no more beyond the flattening itself, and the memo must hold one entry afterwards. It fails with the memo bypassed (100 vs 50 allocations, 0 entries) and passes with it (0 vs 0, 1 entry); it also checks the resolved declarations areRig::panelandPanel::area.go build ./...,go vet ./...,gofmt -l .empty,python3 scripts/changelog.py check.make lint,go test -count=1 ./internal/exec/runtime ./tests/perf ./internal/frontend/grpcandgo test -race ./internal/exec/runtimepass on each head; results are posted in a comment per head.Overlap with open PRs
Dry-merged in a scratch worktree from
origin/developddfbb9446: this head, then each sibling that touchesinternal/exec/runtime(#1606 editseval.go, which this PR changes on one line).fix/sonar-runtime9ed7ce5e3fix/sonar-internal2dc10e486Both merge without conflict; the merged tree's runtime tests are running and the result will be posted in a comment. No landing-order constraint. #1626 touches other runtime files (
subsetting.go,kernel_collections.go,model.go) and adds its own memo tables toModel; both add fields and constructor lines inmodel.go, so whichever lands second merges develop first; dry-merged together they are clean.Checklist
make testandmake lintpass locally (see above for what is still running)changes/unreleased/chain-declarations-memo.changed.mdmake docs-countsrun if a gate count moved (no gate count moved)F4,K5) in the body, docs, or changelog