Repository navigation
Reduce CPU time spent parsing very long build output lines - #5144
Merged
Merged
Conversation
Build output reaches the diagnostic parsers line by line on the extension host, and some tools print very long lines: xcodebuild (Xcode generator) and `ninja -v` echo whole compile commands, and some compilers print caret lines with hundreds of leading spaces. Several parser patterns cost far more than linear time on such a line when it does not match: - gcc: the template-instantiation and "required from" patterns start with `(.*)` and were unanchored, so they were retried from every offset (the first GCC regex dominates the profiles in #4828 and #4229). They are now anchored with `^` and the `m` flag. `.` cannot cross a line terminator, so the leftmost match always starts where `^` matches with `m`: what is matched is unchanged. - msvc: LINKER_REGEX backtracks very heavily on whitespace-led lines. It is now only tried on lines that contain `LNK`, which every match needs. - ghs and diab: the patterns are unanchored and were retried from every quote. They are now only tried on lines that contain text every match needs (`",` plus a location marker for GHS, `",` plus `):` for Diab). Single-call wall timings on synthetic lines, Apple Silicon Mac with Node 22, main versus this change: a 64 KiB quoted -D command line in the GCC parser 1.6 s -> 0.3 ms, a 512-space caret line in the MSVC parser 3.9 s -> 0.2 ms, a 128 KiB command line in the GHS and Diab parsers 0.75 s and 0.96 s -> 0.1 ms. Replaying real xcodebuild output (about 1 MB) through the build output consumer used 1.1-1.6 s of process CPU before and 34-37 ms after (warm medians). The literal checks are necessary conditions of the unchanged patterns, so results are identical (compared with main over several million generated and mutated lines). Lines that contain the required text but are not diagnostics can still be slow in the GHS, Diab and MSVC linker parsers. Adds backend tests: behavior tests that pin what the parsers still recognize (including every line terminator the anchors must handle) and budget tests with lines long enough for the unfixed patterns to need seconds. Related CPU profiles: #4828, #4229
Contributor
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
snehara99
approved these changes
Nov 5, 2026
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.
Context
Build output goes through the diagnostic parsers one line at a time on the extension host, and a few of their regexes get very slow on long lines that don't match. xcodebuild (Xcode generator) and
ninja -vcan print compile commands that run to many KB, and the CPU profiles in #4828 and #4229 both land on the first GCC pattern. This is related to those two, but I'm not claiming it closes either.Changes
^and themflag..can't cross a line terminator, so the leftmost match always started at a line start anyway. What matches doesn't change; the engine just stops retrying from every offset.LNK. It backtracks badly on lines that start with a lot of whitespace, like caret lines.",plus(col.orAt end of sourcefor GHS,",plus):for Diab.Verification & Testing
yarn lintandyarn backendTests. Both pass, 496 tests, 25 of them new.-Dcommand line in the GCC parser, and from about 3.9 s to 0.2 ms for a 512-space caret line in the MSVC parser. Replaying about 1 MB of real xcodebuild output through the build consumer went from 1.1-1.6 s to 34-37 ms of process CPU (warm medians).vscodein place of the extension host. I haven't tested this change in an extension host or on Windows/Linux.