Repository navigation
perf(runtime): memoize the subsetting walks a feature read repeats - #1626
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 e1093ee (Go 1.27.3, same machine):
Overlap: |
4 of 6 tasks
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
Every read of a feature value in the runtime repeats the same walks over the model's subsetting declarations:
relationshipsOfKindrescans the declaration's relationships and allocates a filtered slice per query,relatedFeaturesre-resolves the named targets per query,subsetsTransitivelyre-walks the subsetting chain with a fresh visited set and queue per question, andSubsettingFeatures(inst, …)copies the per-type list into a per-read slice even when the object holds every subsetter. None of these answers can change for a givenModel, so they belong in the model's memo tables besidesubsetters,subsettedandredefined.The cost appeared with the implicit-specialization runtime objects (#1492) and grew with #1512, which route more reads through
subsetsTransitively/relatedFeatures. This change memoizes the four walks per model:relationshipsOfKind→Model.relationshipskeyed by (symbol, kind);relatedFeatures→Model.relatedkeyed by (symbol, owner, kind), stored withslices.Clipso a caller that appends to the result copies instead of writing into the shared slice;subsetsTransitively→Model.subsetsTransitivelykeyed by (feature, owner, target); the walk no longer appends the three source lists into one slice;SubsettingFeatures(inst, typ, name)returns the shared per-type slice wheninstholds every subsetter and filters into a fresh slice only from the first feature it does not hold. The per-type slices are clipped when stored.Measured (
-benchtime 200x, Go 1.27.3 for every column, same machine; allocs/op and B/op are the reliable signal, sec/op is noisy on this VM and omitted):ddfbb9446tests/perfGRPCVerifyConstraint allocs/optests/perfGRPCVerifyConstraint B/opinternal/frontend/grpcInstantiateWarmModel allocs/optests/stressmodelFleetInstantiate/satellites=32 allocs/opGRPCVerifyConstraint recovers 3 547 of the 5 530 allocations #1492/#1512 added per call and all of the bytes; the remaining 1 983 allocations/op are in the binding walks (
bindingWitnesses,resolveBindings,unwrappedDeclMembers,siblingSubsetterValues) and are left to a separate change. A 6-round benchstat table (v0.11.0 | develop | develop+fix) follows in a comment once the quiet rerun finishes.How it was verified
TestRelationshipsOfKindAreCollectedOncePerFeatureandTestSubsettingWalksAreAnsweredOncePerModel(internal/exec/runtime/relationships_memo_test.go):testing.AllocsPerRunover 100 vs 50 repeated walks, each must not allocate more than the other. Both fail with the memo bypassed (100 vs 50 allocations) and pass with it (0 vs 0).go build ./...,go vet ./...,gofmt -l .empty,python3 scripts/changelog.py check.go test -count=1 ./internal/exec/runtime(conformance, traces, robustness) passes;make lint,go test -count=1 ./internal/exec/runtime ./tests/perf ./tests/stressmodel ./internal/frontend/grpc ./internal/frontend/replandgo test -race ./internal/exec/runtimeare running and will be reported in a comment.Overlap with open PRs
Dry-merged in a scratch worktree from
origin/developddfbb9446: this head, then each sibling that touchesinternal/exec/runtime.fix/sonar-runtime9ed7ce5e3fix/sonar-internal2dc10e486Both merge without conflict in either order; the merged tree's runtime and
tests/perftests are being run and the result will be posted in a comment. No landing-order constraint.Checklist
make testandmake lintpass locally (see above for what is still running)changes/unreleased/runtime-subsetting-memo.changed.mdmake docs-countsrun if a gate count moved (no gate count moved)F4,K5) in the body, docs, or changelog