Skip to content

[clang] export a long unterminated line in linear time - #2332

Merged
dulmarod merged 1 commit into
meta:mainfrom
VladimirMakaev:pr/clang-long-line-1125
Nov 26, 2026
Merged

dulmarod merged 1 commit into
meta:mainfrom
VladimirMakaev:pr/clang-long-line-1125

Conversation

@VladimirMakaev

Copy link
Copy Markdown
Contributor

SourceManager rescans a final line without a terminator for every column lookup. Exporting
large generated arrays on one such line therefore takes quadratic time.

// 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. The macOS build
passes, including the Objective-C and Objective-C++ suites that exercise the AST exporter.

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.
@meta-cla meta-cla Bot added the CLA Signed label Nov 25, 2026
@dulmarod
dulmarod merged commit e54c2c1 into meta:main Nov 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants