This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix performance regression after adding GNUstep ObjC runtime
ClosedPublic

Authored by sgraenitz on Aug 17 2023, 12:24 PM.

Details

Summary

We added support for the GNUstep ObjC runtime in 0b6264738f3d. 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 is why LanguageRuntime::FindPlugin invokes
create_callback for each available runtime unconditionally in every Process::ModulesDidLoad.

Diff Detail

Event Timeline

sgraenitz created this revision.Aug 17 2023, 12:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2023, 12:24 PM
sgraenitz requested review of this revision.Aug 17 2023, 12:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2023, 12:24 PM
jasonmolenda accepted this revision.Aug 17 2023, 12:51 PM

Looks good!

This revision is now accepted and ready to land.Aug 17 2023, 12:51 PM
theraven added inline comments.Aug 17 2023, 12:53 PM
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
49

This is a bit unfortunate. I know some downstream users that link the Objective-C runtime components into another .so, so we can't really rely on the name. It would be nice if there were some mechanism for the user to specify the name of the runtime if they're using something non-standard.

jasonmolenda added inline comments.Aug 17 2023, 1:06 PM
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
49

If the runtime was merged in to a library with a known name, we could search for a name in the runtime (if it were the Darwin runtime, objc_msgSend would be a good candidate) in the list of libraries that might have the runtime in them. Doing a "search for a symbol name in any binary that is added" is expensive, doing "search these three solibs for a symbol if they're loaded" is much less expensive, doing "is a solib with this name loaded" is free.

bulbazord accepted this revision.Aug 17 2023, 1:19 PM

This looks fine to me. Did you have the chance to verify that it improves performance of non-objc inferiors on Linux? We'll also probably want to make sure this gets back ported into llvm-17.

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

That would be a nice follow-up!

jingham accepted this revision.Aug 17 2023, 3:16 PM
jingham added inline comments.
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
49

If we can't know up front what library contains the runtime, we could also add a setting for the library name, so we don't have to guess.

Thanks for your quick feedback everyone!

Did you have the chance to verify that it improves performance of non-objc inferiors on Linux?

Nope, but the author of the bug report confirmed that this fixes the issue for them. Since I will be on vacation starting tomorrow, I propose to land this as is.

We'll also probably want to make sure this gets back ported into llvm-17.

Yes, let me check.

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

Thanks for the note. Sounds reasonable. However, this is out of scope for the regression fix.