Repository navigation
perf(semantics): decide a member's root restatement once per symbol - #1368
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)".
|
6 tasks done
6 tasks done
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
Model.restatesRootanswers whether a member redefines or subsets one of the frame roots (Anything::self,Occurrence::timeSlices,incomingTransfers, …) or the coordinate frame's featuring reference.FrameFeatureasks it for every member of every type whose shape is computed, and each call walked the member's redefinition/subsetting chain and built the qualified name of every feature on it (symbols.FQNOfper visited symbol). The answer depends only on the member, so a model instantiating many types that share their library members (thetests/perfsynthetic model: 1 000 part definitions over the sameObjects/Occurrencesmembers) paid the walk 1 000 times per member.The cost became visible when an item's nested actions were counted among its
ownedPerformances(#1310): the 0.11.0 performance measurement ofdevelopagainstv0.10.1hasInstantiateat 2.51 M → 6.34 M allocations, of which 3.82 M → 4.94 M is that merge, and the profile puts the growth underShapeFeatures → FrameFeature → restatesRoot(strings.Builder.grow617 k → 1 570 k,restatesAny1.05 M → 2.19 M cumulative).The change keeps the answer per symbol on the model, in two tables (
restatesFrameRoot,restatesReferenceRoot) journaled with the symbol's document as the other per-symbol memos (allRedefined,redefClosure) are, and only when the resolver frame settled (a walk cut short by a guard is not memoized — the same rule asAllRedefinedFeatures).restatesRootnow takes arootSetnaming which root set is asked about; its four callers are unchanged otherwise.Six interleaved rounds on a quiet machine,
develop(5db0f74) | this branch | #1369 | both (benchstat, allocations exact, p = 0.002 on every moved row):tests/perfInstantiatetests/perfBatchSatisfytests/perfFeaturesOftests/perfGRPCVerifyConstrainttests/stressmodelSatisfy/32v0.10.1:Instantiate2.509 M,BatchSatisfy4.301 M,FeaturesOf4.130 M — with both fixes the first and third are below the previous release (the memo also serves the shapes 0.10.1 computed once per type) and the second is at parity.GRPCVerifyConstraint's growth at #1310 (10.69 k → 14.67 k) is that change's own work (a run begun per nested performance) and is not touched here; the stress constellation'sSatisfyrows have few types and gain nothing from this memo (their remainder overv0.10.1is #1276/#1319's wider type set, as the record states).How it was verified
TestRootRestatementIsDecidedOncePerSymbol(new): a repeatedrestatesRoot/NamesFeaturingReferencequery allocates nothing and answers as the first did; ondeveloptheNamesFeaturingReferencerow allocates 1 per query.go build ./...,go vet ./...,gofmt -l .clean;go testofinternal/semantic/...,internal/exec/runtime,internal/check/...,internal/frontend/lsp,internal/frontend/grpc,tests/model,tests/resolvegreen.Checklist
make testandmake lintpass locally (the packages above; full suite in CI)changes/unreleased/memoize-root-restatement.fixed.mdmake docs-countsrun if a gate count moved (none moved)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