Using EnableSwiftBuildSystemIntegration on M1 Max vs M1 Ultra

EnableSwiftBuildSystemIntegration did make some difference when turned on, for a large mixed ObjC+Swift project when testing this on a 10-Core M1 Max (MBP 16inch, 64 GB RAM).

I just tested the same project on a 20-Core Mac Studio M1 Ultra (128 GB RAM) and surprisingly the build times are exactly the same. No difference apart from +/- a couple of seconds.

Is this expected? I was really hoping the additional cores would get utilized and I'd see perhaps 50% reduction in build time, at least. A little disappointed but hoping this will improve.

What numbers are you actually seeing? From benchmarks Iā€™ve seen, other build systems do get a 2x speed up on the Ultra, so at least it seems possible for Apple to reach expectations here.

My understanding is that most of those benchmarks are for GPU-heavy workloads; at least these do not mirror real-world Xcode usage.

For the same project, I'm seeing ~230 seconds "clean archive" time on a MBP (64 GB, M1 Max) while I'm seeing the same ~230 seconds on the new Mac Studio (128 GB, M1 Ultra).

I've by now tested this on one other fairly "large" mixed project, and build times are ~120 seconds on both. Near zero build time improvements as far as I can tell.

A "clean build" (not an archive) takes roughly 115 seconds on both machines for the same project, give or take a few seconds here and there.

I was hoping to see some improvement (ideally 1.5x) but I'm seeing zero.

There certainly must be room for improvement, given the machine itself is capable of doing better, but I don't see Xcode / Swift compiler utilize the extra cores for now - at least not for the type of mixed projects I've tested this on. I've tried clearing up DerivedData, performing clean builds, waiting for indexing to finish etc but unfortunately a bit disappointed.

Even incremental build times are exactly the same (for minor code changes) - I see 30 seconds on the MBP and 30 seconds on the M1 Ultra for the same changes. I was hoping incremental builds would be at least 1.5x faster (accounting for digital friction) but nope.

My understanding is that most of those benchmarks are for GPU-heavy workloads; at least these do not mirror real-world Xcode usage.

No, various benchmarks for other builds, like WebKit, or cmake or ninja builds, show the 2x improvement.

You may want to investigate where your build time is being spent. Zero improvement is unexpected and doesnā€™t match other Xcode benchmarks Iā€™ve seen.

Sure - but even if build time was spent copying / moving files in a post build phase, I should still see some difference as the times would have offset by faster compilation of actual code. I'm literally seeing the same times.

I know - I'm underwhelmed myself at this point, trying to see if there's something I can tweak, play with, but so far no such luck.

You need to use something like XCLogParser to see where your time is being spent. Since your results are out of line with others, thereā€™s probably something up with your build.

1 Like

Thank looks nice, thanks I'll take a look. I want to believe :innocent:

Both projects seem to show that itā€™s taking that long to build the products / large number of SPMs it depends upon. At first glance thereā€™s nothing glaringly obvious that the build is otherwise ā€œhungā€ on.

Again, Iā€™m perplexed why Iā€™m seeing absolutely zero gains across two completely different projects - same build times. Sure I could now instead spend time trying to perhaps find ways to speed up builds in general but I donā€™t see why compilation itself did not speed up across the 10 cores vs 20 cores.

Iā€™ll continue hunting but it really feels as though Xcode for some odd reason isnā€™t utilizing the additional cores for me.

Side note: every single time I upgraded my hardware over the last 10 years, I would see the gains. Especially from the i9 to the M1 Max. Immediate results. However from the M1 Max to the Ultra it looks as though itā€™s stuck using the same number of cores / threads / build processes somehow and capped at the speed of a single core (times however many itā€™s actually utilizing on both).

Maybe there are some user defaults Xcode is configured with that are messing things up, given I transferred my data using the migration tool. I could try and delete Xcode entirely, wipe out the user defaults and install again :man_shrugging:

Some other data points:

https://mjtsai.com/blog/2022/03/21/m1-ultra-mac-studio-compilation-benchmarks/

This seems to then corroborate with my findings - our project is 95% ObjC and 5% Swift. I'm seeing near zero gains - tried various other things.

Well, if 95% of your code base is objective-c Iā€™m not sure why you expect the 5% swift part to make such a big impact (Amdahl's law - Wikipedia).

I expect ObjC code to utilize the additional cores too, not just Swift. My bad this post is in a Swift Forum (:sweat_smile:).

Sorry - I should add that although the 5% of Swift is part of the main app, the majority of SPMs we use (15+) are 95% Swift. I don't see much gains there too. Again, I should have seen some difference, but the build times remain the same.

Try to play with:
defaults write com.apple.Xcode PBXNumberOfParallelBuildSubtasks 20
or
defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks sysctl -n hw.ncpu

May be current defaults limit the number of cores that can be used.

Sadly this does not help.

If you look at process monitor cpu history, how many cores are saturated during the build on the respective machines?

Most of the times (for most operations, such as checking out git repos, SPMs etc) Xcode seems to only by utilizing the 4 efficiency cores. The 16 performance cores are doing nothing.

When I perform a xcodebuild archive, I see all 20 cores fire up (Activity Panel > CPU History) so it looks like they're being utilized - they come and go though, in between I only see the efficiency cores kick in. What is bothering me is that I'm seeing no improvements in overall compilation time.

I've spent a day trying to optimize build times but have gotten nowhere. I'm going to stop now, assuming this will improve with future xcode updates ĀÆ\(惄)/ĀÆ

Here's what I see (taken in the middle of an archive)

This is an interesting graph. You can see all cores being utilized - this is when Xcode was indexing in the background (nothing being built actively). Once it finished indexing, I started the build and saw core utilization drop across all performance cores (near the middle of the graph). Only the efficiency cores plus a few performance cores are seen being utilized (I've noticed that for most things in Xcode, only the 4 efficiency cores are utilized. I would have thought for a desktop mac with unlimited power draw, it would prefer using the performance cores.)

I'm seeing something very similar and commented about it here

However I am noticing the ObjC compilations are simply much slower. On my Ultra Studio a typical file is taking between 5 seconds and 7 seconds per file!!, whereas on the MBP (Pro) the same files are taking 0.7 and 1.2 seconds. So overall my total build is slower on the Ultra vs MBP. After investigating all the possible compilation settings I could only assume its something to do with all the -I includes (there are over 2500 per file). Since my project is around 10% Swift, I see there is no discernible difference with this flag, but given the major issue is with ObjC it was not unexpected!