Skip to content

Commit af2eb83

Browse files
[lldb] Fix performance regression after adding GNUstep ObjC runtime
We added support for the GNUstep ObjC runtime in 0b62647. In order to check if the target process uses GNUstep we run an expensive symbol lookup in `CreateInstance()`. This turned out to cause a heavy performance regression for non-GNUstep inferiors. This patch puts a cheaper check in front, so that the vast majority of requests should return early. This should fix the symptom for the moment. The conceptual question remains: Why does `LanguageRuntime::FindPlugin` invoke `create_callback` for each available runtime unconditionally in every `Process::ModulesDidLoad`? Reviewed By: jasonmolenda, jingham, bulbazord Differential Revision: https://reviews.llvm.org/D158205
1 parent 9e11a6d commit af2eb83

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ void GNUstepObjCRuntime::Terminate() {
3737
PluginManager::UnregisterPlugin(CreateInstance);
3838
}
3939

40+
static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp,
41+
const llvm::Triple &TT) {
42+
if (!module_sp)
43+
return false;
44+
const FileSpec &module_file_spec = module_sp->GetFileSpec();
45+
if (!module_file_spec)
46+
return false;
47+
llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
48+
if (TT.isOSBinFormatELF())
49+
return filename.starts_with("libobjc.so");
50+
if (TT.isOSWindows())
51+
return filename == "objc.dll";
52+
return false;
53+
}
54+
55+
static bool ScanForGNUstepObjCLibraryCandidate(const ModuleList &modules,
56+
const llvm::Triple &TT) {
57+
std::lock_guard<std::recursive_mutex> guard(modules.GetMutex());
58+
size_t num_modules = modules.GetSize();
59+
for (size_t i = 0; i < num_modules; i++) {
60+
auto mod = modules.GetModuleAtIndex(i);
61+
if (CanModuleBeGNUstepObjCLibrary(mod, TT))
62+
return true;
63+
}
64+
return false;
65+
}
66+
4067
LanguageRuntime *GNUstepObjCRuntime::CreateInstance(Process *process,
4168
LanguageType language) {
4269
if (language != eLanguageTypeObjC)
@@ -50,6 +77,9 @@ LanguageRuntime *GNUstepObjCRuntime::CreateInstance(Process *process,
5077
return nullptr;
5178

5279
const ModuleList &images = target.GetImages();
80+
if (!ScanForGNUstepObjCLibraryCandidate(images, TT))
81+
return nullptr;
82+
5383
if (TT.isOSBinFormatELF()) {
5484
SymbolContextList eh_pers;
5585
RegularExpression regex("__gnustep_objc[x]*_personality_v[0-9]+");
@@ -176,18 +206,8 @@ void GNUstepObjCRuntime::UpdateISAToDescriptorMapIfNeeded() {
176206
}
177207

178208
bool GNUstepObjCRuntime::IsModuleObjCLibrary(const ModuleSP &module_sp) {
179-
if (!module_sp)
180-
return false;
181-
const FileSpec &module_file_spec = module_sp->GetFileSpec();
182-
if (!module_file_spec)
183-
return false;
184-
llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
185209
const llvm::Triple &TT = GetTargetRef().GetArchitecture().GetTriple();
186-
if (TT.isOSBinFormatELF())
187-
return filename.starts_with("libobjc.so");
188-
if (TT.isOSWindows())
189-
return filename == "objc.dll";
190-
return false;
210+
return CanModuleBeGNUstepObjCLibrary(module_sp, TT);
191211
}
192212

193213
bool GNUstepObjCRuntime::ReadObjCLibrary(const ModuleSP &module_sp) {

0 commit comments

Comments
 (0)