Repository navigation
perf: speed up dynamic XML output and constrained scalars - #137
Merged
Merged
Conversation
This was referenced Oct 3, 2026
nth-bailey
marked this pull request as ready for review
October 4, 2026 03:58
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.
Dynamic XML parsing clones rich scalar definitions for every occurrence and recompiles each scalar regex for every value. Writing also formats lists through intermediate strings and sends append-only output through a cursor. This change borrows frame-owned scalar metadata by index, reuses anchored regexes in a concurrent cache, formats lists into one string, selects prevalidation obligations before traversing values, and writes directly to the output vector.
The cache retains 16 entries with keys up to 4,096 bytes; larger patterns compile uncached. Compilation and matching occur outside its lock. Salted victim selection avoids systematic misses in a 17-pattern cycle without increasing capacity. Schema edits before sharing, validation errors, split text, nested/mixed order and nil reads retain their behavior.
Three alternating Criterion processes per revision confirm 18–20% faster plain writes and about 45% faster enum reads versus 0.34.6. Warm pattern fixtures improve 42–44× on reads and 92–104× on writes. With 17 distinct patterns, reads improve 6.6× and writes 36×; at 64 patterns, reads are approximately unchanged and writes improve 7×. These are fixture-specific results, and the cache limits entries/key retention rather than total regex memory. Plain catalog reads remain about 5% slower than 0.27.0.
The report links exact source revisions, locks, every retained sample, instruction profiles and positive/negative experiments. Generated model sources are byte-identical; four-round XML/Serde controls show no material batch slowdown, with small micro-operation differences retained in the tables.
Validation:
Two newly noticed correctness limitations—escaped XSD enumeration attributes and writing nil mixed scalars—have minimal reproducers showing identical control/candidate errors. They remain separate follow-up work. Main is unchanged; this PR is a draft for reviewing the optimization and its evidence.