Significant performance regression of DYLD SPI (macOS Big Sur and iOS 14+)

Hello,

Me and my colleagues noticed a significant performance degradation during debug process. We use Xcode 12.5 and working on a large Swift app with 150+ modules. After migration to macOS 11.3-11.4, our application started to freeze on every dynamic linked library load.

First, we tried to research problem on our side, but with no success. Then we started to profile Xcode instruments (lldb and debugserver). I noticed that calling dyld SPI methods (dyld_process_info_create() in debugserver) took the most of processor time during the app process freeze.

I made a special debugserver build with additional logging to OSLog and measured every dyld_process_info_create() method call duration. I found out that every dynamic linked library load caused dyld_process_info_create() method call with ~300ms duration, and this call caused app freeze. Dozens of such calls occurs when our applications are launched in debug mode, so app process are freezes for minutes.

As an experiment, we tried to profile the same dyld SPI calls on macOS 11.2.1, and dyld_process_info_create() call takes only ~10ms. It is much faster and our app works normally.

Many other users also reported an issue: Xcode 12.5 very slow launch time f… | Apple Developer Forums

Some users also tried to reduce dyld SPI API call count: rG8dd106028b15

We used iOS simulator, but on iOS 14.6 problem is also reproduced. Unfortunately, I can't use custom debugserver build on iOS to prove.

DYLD SPI is a part of Darwin project, so I duplicated this report to Apple Feedback Assistant.

3 Likes

Hi Alexander, thanks for the very detailed report! It looks like the issue you linked to has been solved on Xcode 13, could you test on that version and see if it still happens?

Unfortunately, our project is not ready for Xcode 13. We are working for migration to the new build system. But I tried to debug app on Xcode 12.5 and 12.5.1 with Xcode 13 version of debugserver and issue is still present. Also, I tried a debugserver build from master branch of llvm project.

You could try a workaround by running this on your terminal:

echo settings set plugin.process.gdb-remote.packet-timeout 300 >> ~/.lldbinit

Thanks, @augusto2112 , but I didn't notice any changes. As far as I know, this workaround helps to fix debugger connection timeout issue. But we never experienced this issue, connection to debugserver seems pretty stable. And debug session continues after these "freezes" caused by DYLD SPI.

The only workaround we found is to decrease dyld_process_info_create() call count. The ways to achive:

  • Use monolith app architecture without dynamic linked libraries.
  • Disable "lazy" libraries loading.

These methods improves debug experience for developers, but significantly increases app startup time and degrades the user experience.
Is it possible to roll back the implementation of DYLD SPI?

@Chupik can you please verify that you're indeed using Xcode 12.5.1? Both 12.5.1 and Xcode 13 Beta are caching the calls to dyld_process_info_create(). If you're still seeing a significant slowdown with those versions I think this might be a different issue. If that's the case it would be helpful to capture another trace of both debugserver and lldb-rpc-server and attach it to the feedback report.

PS: Can you please put the FB number here so I can take a look?

Yes, I am using Xcode 12.5.1. Also, I tried to use debugserver build from master llvm branch, that also contained that optimization. This fix reduced dyld_process_info_create() calls for platform request and improved debugger attach time. But libraries load events still triggers applications freezes on Big Sur 11.3+.

Case number in Feedback Assistant: FB9349767
I attached Time Profiler trace to feedback.

Hello,
I checked our project on Xcode 13 Beta 4 and MacOS 11.4 and didn't see any difference.

The last idea I have is to merge old dyld SPI implementation right into debugserver code and measure the performance or somehow link debugserver to old libdyld.dylib version.

There are some updates. I received feedback from Apple Dev Team. They said that the issue has been resolved in macOS 12 beta 4. I checked this macOS version and confirm that debugger performance is the same as in Big Sur 11.2.1.

iOS is not yet fixed (I checked 15 beta 5).

1 Like
Terms of Service

Privacy Policy

Cookie Policy