[clang] [clang][deps] Check for "__preprocessed_" before the line-by-line walk (PR #239449)
Vladimir Shiryaev via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 17:47:22 PST 2026
https://github.com/tagolog created https://github.com/llvm/llvm-project/pull/239449
`isPreprocessedModuleFile()` scans the whole source line by line,
looking for `__preprocessed_module` or `__preprocessed_import`
directives. This scan is pretty expensive.
Add a fast path by checking for the presence of the `__preprocessed_`
string. On `swiftlang/llvm-project`, a cache hit through `clang-cache`
with its default inline dependency scan drops
- from 201.4 to 189.8 ms (-5.7%) on Windows
- from 107.7 to 100.3 ms (-6.9%) on Linux
>From 04760aae4f68f469c67554baa0d8528a5e2bfbed Mon Sep 17 00:00:00 2001
From: Vladimir Shiryaev <w at tagolog.com>
Date: Thu, 5 Nov 2026 12:02:34 -0700
Subject: [PATCH] [clang][deps] Check for "__preprocessed_" before the
line-by-line walk
isPreprocessedModuleFile() scans the whole source line by line,
looking for "__preprocessed_module" or "__preprocessed_import"
directives. This scan is pretty expensive.
Add fast path by checking for the presence of "__preprocessed_" string.
On `swiftlang/llvm-project`, a cache hit through
`clang-cache` with its default inline dependency scan drops
- from 201.4 to 189.8 ms (-5.7%) on Windows
- from 107.7 to 100.3 ms (-6.9%) on Linux
---
clang/lib/Lex/DependencyDirectivesScanner.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index ccf80c4a9f5728..430f46d0ba7f65 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -1212,6 +1212,11 @@ ModuleUnitKind clang::scanInputForCXX20ModuleUnit(StringRef Source) {
}
bool clang::isPreprocessedModuleFile(StringRef Source) {
+ // Fast path: a file without "__preprocessed_" has neither directive.
+ // Skipping the line-by-line walk speeds up the scan.
+ if (!Source.contains("__preprocessed_"))
+ return false;
+
const char *First = Source.begin();
const char *const End = Source.end();
More information about the cfe-commits
mailing list