Skip to content

Commit ac29c35

Browse files
committed
[lldb/Platform] Skip very slow xcrun queries for simulator platforms, NFC
GetXcodeSDK() consistently takes over 1 second to complete if the queried SDK is missing, because `xcrun` doesn't cache negative lookups. Because there are multiple simulator platforms, this can add 4+ seconds to `lldb -b some_object_file.o`. To work around this, skip the call to GetXcodeSDK() when setting up simulator platforms if the specified arch doesn't have what looks like a simulator triple. Some other ways to fix this: - Fix caching in xcrun (rdar://74882205) - Test for arch compat before calling SomePlatform::CreateInstance() (much larger change) Differential Revision: https://reviews.llvm.org/D98272
1 parent 361e9bf commit ac29c35

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,16 @@ uint32_t PlatformAppleSimulator::FindProcesses(
505505
return process_infos.size();
506506
}
507507

508+
/// Whether to skip creating a simulator platform.
509+
static bool shouldSkipSimulatorPlatform(bool force, const ArchSpec *arch) {
510+
// If the arch is known not to specify a simulator environment, skip creating
511+
// the simulator platform (we can create it later if there's a matching arch).
512+
// This avoids very slow xcrun queries for non-simulator archs (the slowness
513+
// is due to xcrun not caching negative queries (rdar://74882205)).
514+
return !force && arch && arch->IsValid() &&
515+
!arch->TripleEnvironmentWasSpecified();
516+
}
517+
508518
static llvm::StringRef GetXcodeSDKDir(std::string preferred,
509519
std::string secondary) {
510520
llvm::StringRef sdk;
@@ -530,6 +540,8 @@ struct PlatformiOSSimulator {
530540
}
531541

532542
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
543+
if (shouldSkipSimulatorPlatform(force, arch))
544+
return nullptr;
533545
llvm::StringRef sdk;
534546
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.Internal.sdk"));
535547
if (sdk.empty())
@@ -578,6 +590,8 @@ struct PlatformAppleTVSimulator {
578590
}
579591

580592
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
593+
if (shouldSkipSimulatorPlatform(force, arch))
594+
return nullptr;
581595
return PlatformAppleSimulator::CreateInstance(
582596
"PlatformAppleTVSimulator", g_tvos_description,
583597
ConstString(g_tvos_plugin_name),
@@ -619,6 +633,8 @@ struct PlatformAppleWatchSimulator {
619633
}
620634

621635
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
636+
if (shouldSkipSimulatorPlatform(force, arch))
637+
return nullptr;
622638
return PlatformAppleSimulator::CreateInstance(
623639
"PlatformAppleWatchSimulator", g_watchos_description,
624640
ConstString(g_watchos_plugin_name),

0 commit comments

Comments
 (0)