Repository navigation
[clang] export a long unterminated line in linear time - #2332
Merged
Merged
Conversation
SourceManager rescans a final line without a terminator for every column lookup. Exporting
large generated arrays on one such line therefore takes quadratic time.
```cpp
// blob.inc contains one long line without a final newline
constexpr unsigned char blob[] = {
#include "blob.inc"
};
```
Cache the final-line start while visiting a file and derive its columns directly. Keep
SourceManager for other locations and line directives, preserving exported location fields.
Compute macro locations only where they are used.
Limitations: line directives and frequent expansion/spelling file switches can retain the
old scanning cost; the cache holds one file at a time.
## Test plan
Native build and 73 Linux suites plus annotations pass, with no regeneration. All 34 paired
AST exports match, including macros and line directives. The 100,000-element test reaches
60 CPU seconds before the change and completes in 0.30 seconds afterward. Full fork macOS
suite required before opening the PR.
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.
SourceManager rescans a final line without a terminator for every column lookup. Exporting
large generated arrays on one such line therefore takes quadratic time.
Cache the final-line start while visiting a file and derive its columns directly. Keep
SourceManager for other locations and line directives, preserving exported location fields.
Compute macro locations only where they are used.
Limitations: line directives and frequent expansion/spelling file switches can retain the
old scanning cost; the cache holds one file at a time.
Test plan
Native build and 73 Linux suites plus annotations pass, with no regeneration. All 34 paired
AST exports match, including macros and line directives. The 100,000-element test reaches
60 CPU seconds before the change and completes in 0.30 seconds afterward. The macOS build
passes, including the Objective-C and Objective-C++ suites that exercise the AST exporter.