Skip to content

Commit 821a667

Browse files
committed
Make the warmup of the SwiftASTContext cache lazy (NFC)
This is in preparations for later refactorings. The (pointless) effect right now is that in 99% of the cases the cache warmup is now delayed until the ProcessModule loop. rdar://81717792
1 parent 4eb9dc6 commit 821a667

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,29 +2131,32 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
21312131
handled_sdk_path = true;
21322132
}
21332133

2134-
if (target.GetSwiftCreateModuleContextsInParallel()) {
2135-
// The first call to GetTypeSystemForLanguage() on a module will
2136-
// trigger the import (and thus most likely the rebuild) of all
2137-
// the Clang modules that were imported in this module. This can
2138-
// be a lot of work (potentially ten seconds per module), but it
2139-
// can be performed in parallel.
2140-
const unsigned threads =
2141-
repro::Reproducer::Instance().IsReplaying() ? 1 : 0;
2142-
llvm::ThreadPool pool(llvm::hardware_concurrency(threads));
2143-
for (size_t mi = 0; mi != num_images; ++mi) {
2144-
auto module_sp = target.GetImages().GetModuleAtIndex(mi);
2145-
pool.async([=] {
2146-
auto val_or_err =
2147-
module_sp->GetTypeSystemForLanguage(lldb::eLanguageTypeSwift);
2148-
if (!val_or_err) {
2149-
llvm::consumeError(val_or_err.takeError());
2150-
}
2151-
});
2134+
auto warmup_astcontexts = [&]() {
2135+
if (target.GetSwiftCreateModuleContextsInParallel()) {
2136+
// The first call to GetTypeSystemForLanguage() on a module will
2137+
// trigger the import (and thus most likely the rebuild) of all
2138+
// the Clang modules that were imported in this module. This can
2139+
// be a lot of work (potentially ten seconds per module), but it
2140+
// can be performed in parallel.
2141+
const unsigned threads =
2142+
repro::Reproducer::Instance().IsReplaying() ? 1 : 0;
2143+
llvm::ThreadPool pool(llvm::hardware_concurrency(threads));
2144+
for (size_t mi = 0; mi != num_images; ++mi) {
2145+
auto module_sp = target.GetImages().GetModuleAtIndex(mi);
2146+
pool.async([=] {
2147+
auto val_or_err =
2148+
module_sp->GetTypeSystemForLanguage(lldb::eLanguageTypeSwift);
2149+
if (!val_or_err) {
2150+
llvm::consumeError(val_or_err.takeError());
2151+
}
2152+
});
2153+
}
2154+
pool.wait();
21522155
}
2153-
pool.wait();
2154-
}
2156+
};
21552157

21562158
if (!handled_sdk_path) {
2159+
warmup_astcontexts();
21572160
for (size_t mi = 0; mi != num_images; ++mi) {
21582161
ModuleSP module_sp = target.GetImages().GetModuleAtIndex(mi);
21592162
if (!HasSwiftModules(*module_sp))
@@ -2268,6 +2271,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
22682271
const bool use_all_compiler_flags =
22692272
!got_serialized_options || target.GetUseAllCompilerFlags();
22702273

2274+
warmup_astcontexts();
22712275
for (size_t mi = 0; mi != num_images; ++mi) {
22722276
std::vector<std::string> extra_clang_args;
22732277
ProcessModule(target.GetImages().GetModuleAtIndex(mi), m_description,

0 commit comments

Comments
 (0)