Skip to content

Make the warmup of the SwiftASTContext cache lazy (NFC) #3324

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
merged 1 commit into from
Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,29 +2131,32 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
handled_sdk_path = true;
}

if (target.GetSwiftCreateModuleContextsInParallel()) {
// The first call to GetTypeSystemForLanguage() on a module will
// trigger the import (and thus most likely the rebuild) of all
// the Clang modules that were imported in this module. This can
// be a lot of work (potentially ten seconds per module), but it
// can be performed in parallel.
const unsigned threads =
repro::Reproducer::Instance().IsReplaying() ? 1 : 0;
llvm::ThreadPool pool(llvm::hardware_concurrency(threads));
for (size_t mi = 0; mi != num_images; ++mi) {
auto module_sp = target.GetImages().GetModuleAtIndex(mi);
pool.async([=] {
auto val_or_err =
module_sp->GetTypeSystemForLanguage(lldb::eLanguageTypeSwift);
if (!val_or_err) {
llvm::consumeError(val_or_err.takeError());
}
});
auto warmup_astcontexts = [&]() {
if (target.GetSwiftCreateModuleContextsInParallel()) {
// The first call to GetTypeSystemForLanguage() on a module will
// trigger the import (and thus most likely the rebuild) of all
// the Clang modules that were imported in this module. This can
// be a lot of work (potentially ten seconds per module), but it
// can be performed in parallel.
const unsigned threads =
repro::Reproducer::Instance().IsReplaying() ? 1 : 0;
llvm::ThreadPool pool(llvm::hardware_concurrency(threads));
for (size_t mi = 0; mi != num_images; ++mi) {
auto module_sp = target.GetImages().GetModuleAtIndex(mi);
pool.async([=] {
auto val_or_err =
module_sp->GetTypeSystemForLanguage(lldb::eLanguageTypeSwift);
if (!val_or_err) {
llvm::consumeError(val_or_err.takeError());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what kind of errors might these be? I am wondering whether we should log these.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read llvm::Expected<TypeSystem &> TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language, Module *module, bool can_create) { right, it never returns an error.

}
});
}
pool.wait();
}
pool.wait();
}
};

if (!handled_sdk_path) {
warmup_astcontexts();
for (size_t mi = 0; mi != num_images; ++mi) {
ModuleSP module_sp = target.GetImages().GetModuleAtIndex(mi);
if (!HasSwiftModules(*module_sp))
Expand Down Expand Up @@ -2268,6 +2271,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
const bool use_all_compiler_flags =
!got_serialized_options || target.GetUseAllCompilerFlags();

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