chore(compiler): perf speedup through type-state sharing - #1895
Open
klondikedragon wants to merge 4 commits into
Open
chore(compiler): perf speedup through type-state sharing#1895klondikedragon wants to merge 4 commits into
klondikedragon wants to merge 4 commits into
Conversation
Avoid deep-cloning exact object/array Collections and TypeDefs on every nested path write during progressive typecheck. Co-authored-by: Cursor Grok 4.5 Signed-off-by: Klondike Dragon <klondikedragon@gmail.com>
Wrap known fields in SharedMap so TypeState forks clone cheaply and writes copy-on-write through make_mut. Co-authored-by: Cursor Grok 4.5 Signed-off-by: Klondike Dragon <klondikedragon@gmail.com>
TypeState forks (if arms, compile_expr snapshots) clone locals cheaply until make_mut; ~2.7x faster compile on a large --program workload in the ladder harness. Co-authored-by: Cursor Grok 4.5 Signed-off-by: Klondike Dragon <klondikedragon@gmail.com>
Open
15 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.
Summary
Implements type-state sharing: three independent optimizations that make the compiler's type state cheaper to clone and merge:
Kindinserts and assignment typesArc-sharedCollectionknown mapsArc-sharedLocalEnvbindingsWhy? our production VRL programs take 20-30 seconds to compile (and thus for vector to start), and profiling demonstrated this as a top hot spot.
Split out of #1865 at @pront's request (the two are dijoint but greatly complement each other).
Using the synthetic ladder test that exercises this hot spot in the compiler (using
--warmup 2 --repeat 5, medians) gives:--fields-disjoint)This is a constant-factor win, not the asymptotic win of #1865... it lowers the cost of each type-state operation but does not change the complexity class, which is why the speedup shrinks as arm count grows and the quadratic term fixed by #1865 still takes over.
Once #1865 fixes the quadratic work, this optimization cuts a larger slice of the remaining overhead, so further observed speedups with this on top of #1865 was a further 2.0x to 3.3x (521 ms to 174 ms at 160 arms; 1395 ms to 427 ms on the wide-arm shape).
Change Type
Is this a breaking change?
How did you test this PR?
Full unit test coverage from the existing suite, plus the additional unit tests added in #1865 that further cover if-else ladder cases. The 26 complex production VRL programs also were shown to identical typing outputs before/after.
Does this PR include user facing changes?
our guidelines.
Checklist
run
dd-rust-license-tool writeand commit the changes. More details here.References
Split off of #1865.