-
Notifications
You must be signed in to change notification settings - Fork 7
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
Slow linking with lld #38
Comments
Interesting, I think the best way to investigate further would be to run with instruments attached and see where the time is going. The response file isn't really enough to know where the hot path is |
I ran the time profiler on my repro case and that's the heaviest stack trace recorded:
See the full trace. For the measurement I've used linker that I compiled myself from EDIT: The Anyway, that's sums up to ~32250 checks of dylibs presence in our case. |
Those 32250 checks are mostly duplicates right? If so I think we can safely cache the results of that function and return that |
FWIW if they're static frameworks it would probably be ideal if they weren't discovered this way and instead were directly passed to the linker (which rules_apple and bazel are generally doing now with some recent changes). But also clearly lld should handle this. Can you try off the same sha with this patch https://reviews.llvm.org/D147960 |
Here's the trace after the patch: Technically there are not so many I/O actions anymore, still the linking time increased by a minute 🤔 I'm not sure how to debug it further.
I guess that'd be ideal. We're planning to switch to rules_apple but that won't happen anytime soon I'm afraid.
Quite a lot of them is something like that:
So perhaps the patch could be even more improved by looking into file names, if possible. |
Can you attach that trace? Oof with different paths I bet the cache isn't really even helping (you could add logs for hits / misses). In that trace what's under that 4 minute unsymbolicated thing? I don't think it's technically safe to cache by file name given it's technically possible to have frameworks of the same name at different paths that are actually different |
You might be able to ignore auto load commands all together, but that would require at least a bit of manually passing some linker flags for swift. But I think that would sidestep this entirely. If that did work that could be added in rules_iOS to disable auto linking for its frameworks and then you wouldn't have to do anything manually |
Here's the trace. It's a different one, though still with the patch applied - ld64.lld-repro-patched.trace.zip
Which flags are you referring to? 🤔
I will try that when I have a minute and get back to you. I think it actually helps a bit. If you look on the trace, you can see that |
So, I added the logs for hits/misses and I can see misses mostly. Only system frameworks distributed with Xcode seems to be cached. Quite often the code falls into |
Ah yes there is a bug in the logic because of how it's called, I updated my diff can you try again?
pass |
also if you could share an entire reproducer with me that would be super helpful for debugging. to do that you can pass |
I did, nothing new. Mostly misses are logged and no visible improvement in the time profiler.
Will try that, thanks.
Sorry, can't share that. We can sync on the Slack about further debug steps I could take, let me know. |
Two weeks ago we adapted the
lld
linker to our project, unfortunately after that we observed much longer build times on CI. After investigating, it turned out that the problem is caused by the new linker.Running the linking of UI tests target locally, I observe that a process is created that takes 100% of the CPU time. The whole thing even takes more than 300s(!), where the default linker, finishes its work in ~3s.
We're using mix of Swift and ObjC code, as well as notable number of precompiled libraries. Project is heavily modularised, most of the modules are linked statically.
I attach edited contents of the response.txt file generated by the
--reproduce
flag. Hope it will be helpful. I tried to reproduce the error in dummy project but unfortunately without success.The text was updated successfully, but these errors were encountered: