Emitting Module takes 25x the time in XCode 15.1 beta

There seems to be some degradation in the "emit module" phase of building between XCode 15.0 ( Swift ) and XCode 15.1 Beta ( Swift )

We have several different frameworks and apps in my XCWorkspace. In the 15.1 beta, most of them compile around the same speed, or slightly faster. However one framework we have seems to take over 10x as long as before. When looking into it in the Xcode timeline, almost all of the time is spent on the "Emitting Module" phase. It went from ~56 seconds to ~1440 seconds on a clean build. Also some of the files do seem to compile quite a bit slower, but this is a large bottle neck with nothing else really happening in the timeline besides "emitting module" at the time. If i watch Activity Monitor at the time, my CPU has a swift-frontend process pegged at 100% during that time. But otherwise nothing seems suspicious. Comparing the output the framework is almost identical in size and I don't see anything else really noticeable.

Any ideas on what would cause this huge discrepancy ?

1 Like

Hey @sasouth , could you share a captured spindump when the slowness happens?

1 Like

I just identified and fixed a case where we saw this happening when a module has a very large number of Swift files in it. (It could also happen with a large number of macro expansions). For the project where we had seen the regression, the "Emitting Module" phase went from 300s down to 32s.

It's likely to be the same as what you're seeing. We can verify that with a spindump if you're able to capture one, or we can kick off a toolchain build if you'd like to try that.

[Edit: for those who are curious, the compiler had a linear-time algorithm to map from its internal representation of a source location to the source file in which that location occurs. The algorithm has been linear-time "forever", but a recent bug fix put it into a hot path. The fix is to turn it into a logarithmic algorithm with a single-element most-recently-used cache.]



I took a spindump, though I cut out only the swift-frontend portion. Hopefully that is sufficient.

Thank you, @sasouth ! It looks related to the issue Doug has put up a fix for.

Forgive me for my ignorance, but is it possible to test this out prior to it being included in the new xcode. I know swift can be distributed as a stand alone, but i'm not sure if it's possible to update the integration with XCode or if you just have to wait.

Is it known yet if this fix will be included in the 15.1 RC ?

We could potentially test out this fix by installing/running an OSS toolchain that has this fix. More context can be found here: Swift.org - Download Swift

I saw this comment on the PR:

[...] none of the test projects there have a huge number of Swift files in a single target.

Could someone please sketch an outline of how I might contribute such a test?

I work on a target with a "huge number of Swift files" every working day and it'd be great if CI could catch performance problems or regressions so I can update my Xcode without anxiety about how my productivity will be impacted.


Has there been any update to this? We have a project that takes 5-9 minutes longer to build on Xcode 15.2 with a specific SDK we have to implement and it is really affecting our developer workflow.

In the meantime, we have to do our development on a branch with this SDK not imported. We didn't have this problem before Xcode 15 either.

No updates that I am aware of. Struggling with the same issue on this side.

Is this fixed in Xcode 15.1? I'm still facing with this :disappointed_relieved: