Skip to content

🍒 [clang][deps][modules] Speed up dependency scanning (2) #9573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jansvoboda11
Copy link

This PR cherry-picks upstream commits that speed up the dependency scanning. This should be mostly NFC.

This PR builds on top of llvm#113984 and attempts to avoid allocating input
file paths eagerly. Instead, the `InputFileInfo` type used by
`ASTReader` now only holds `StringRef`s that point into the PCM file
buffer, and the full input file paths get resolved on demand.

The dependency scanner makes use of this in a bit of a roundabout way:
`ModuleDeps` now only holds (an owning copy of) the short unresolved
input file paths, which get resolved lazily. This can be a big win, I'm
seeing up to a 5% speedup.

(cherry picked from commit 9d4837f)
(cherry picked from commit c605fa3)
The `FileManager` sharing between module-building `CompilerInstance`s
was disabled a while ago due to `FileEntry::getName()` being unreliable.
Now that we use `FileEntryRef::getNameAsRequested()` in places where it
matters, re-enabling `FileManager` is sound and improves performance of
`clang-scan-deps` by ~6.2%.

(cherry picked from commit a6637ae)
(cherry picked from commit 18e0eb4)
This patch removes `ASTWriter::Context` and starts passing `ASTContext
&` explicitly to functions that actually need it. This is a
non-functional change with the end-goal of being able to write
lightweight PCM files with no `ASTContext` at all.

(cherry picked from commit 53e49f1)
… only (llvm#115237)

This PR builds on top of
llvm#115235 and makes it possible
to call `ASTWriter::WriteAST()` with `Preprocessor` only instead of full
`Sema` object. So far, there are no clients that leverage the new
capability - that will come in a follow-up commit.

(cherry picked from commit a2f9d1d)
This patch builds on top of
llvm#115237 and
llvm#115235, only passing the
`Preprocessor` object to `ASTWriter`. This reduces the size of scanning
PCM files by 1/3 and speeds up scans by 16%.

(cherry picked from commit 25d1ac1)
@jansvoboda11
Copy link
Author

@swift-ci please test

@jansvoboda11
Copy link
Author

swiftlang/swift#77557
@swift-ci please test

@jansvoboda11 jansvoboda11 merged commit 7649a05 into stable/20240723 Nov 12, 2024
3 checks passed
@jansvoboda11 jansvoboda11 deleted the jan_svoboda/stable-20240723-scanner-perf-2 branch November 12, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant