Repository navigation
Conversation
The first query in a process deserializes the lexer's ATN, which builds large Unicode character sets one interval at a time. IntervalSet::add walked the whole list for each one, which was about half of the first query's compile time. An interval that goes into an empty set, or starts after the last one without touching it, is now appended directly; the result is the same. This is a local patch on the vendored ANTLR 4.13.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
This work was produced with the help of language models.
Fixes #1301. Part of #1290.
The first query in a process deserialized the lexer's ATN, which builds large Unicode character sets one interval at a time, and
IntervalSet::addwalked the whole interval list for each one: about half of the first query's 9.39 ms compile time forRETURN 1(query-summary time, median of 8 processes). The 0.18 ms in #1290 is a later query.Fix. An interval that goes into an empty set, or starts after the last interval without touching it, is appended directly; any other interval takes the existing loop, so the resulting set is the same. This is a local patch to the vendored runtime (ANTLR 4.13.1, marked in the source); upstream 4.13.2 and the dev branch have the same loop.
Performance. First query compile 9.39 → 5.16 ms, 77.7M → 42.0M instructions; later queries unchanged. Mallocs are unchanged too: about 68.4K for the first query (within run-to-run noise) and 601 per later
RETURN 1at one thread. The rest of the first compile is ANTLR filling its prediction cache on first use.Tests.
AntlrIntervalSetTest.AddKeepsCanonicalForm: random and sorted inserts plus touching intervals, against brute-force membership and the canonical sorted, disjoint, non-adjacent form.EofMergesOnlyWithTouchingRange: EOF (-1) merges with a range starting at 0 and stays separate from one starting at 1.EmptyIntervalAndRangeLimits: an empty interval is ignored, and appends and merges nearSSIZE_MAXgive the same set. All three fail if the fast path appends an interval that touches the last one. Full ctest on this branch: 3103/3103.Independent of #1297 and #1300; with all three the first query compiles in 5.1 ms and executes in 0.33 ms (query-summary median of 8 processes).