Skip to content

chore(compiler): perf speedup through type-state sharing - #1895

Open
klondikedragon wants to merge 4 commits into
vectordotdev:mainfrom
itlightning:perf/typestate-sharing
Open

chore(compiler): perf speedup through type-state sharing#1895
klondikedragon wants to merge 4 commits into
vectordotdev:mainfrom
itlightning:perf/typestate-sharing

Conversation

@klondikedragon

Copy link
Copy Markdown
Contributor

Summary

Implements type-state sharing: three independent optimizations that make the compiler's type state cheaper to clone and merge:

  • In-place Kind inserts and assignment types
  • Arc-shared Collection known maps
  • Arc-shared LocalEnv bindings

Why? 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:

shape base this PR speedup
20 arms, 40 fields 330 ms 92 ms 3.6x
80 arms 4502 ms 2450 ms 1.8x
wide arm body (82 arms, 8 coalesce, chain 3) 16095 ms 6229 ms 2.6x
growing event Kind (--fields-disjoint) 13975 ms 9713 ms 1.4x

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

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

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?

  • Yes. Please add a changelog fragment based on
    our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

References

Split off of #1865.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant