Swift 5.7 / Xcode 14 incremental build time 10x slower than Swift 5.6 / Xcode 13

I'm not entirely sure if we're seeing the same issue described here, or something else but after moving to Xcode 14 there is some kind of bug that is adding a ~52s increase in an incremental build where I'm just making a relatively isolated one line change in a view controller.

In Xcode 13.4.1, the same incremental build takes ~23s and in Xcode 14.1 we're up to 75s which suggests that this one step is the issue. Furthermore, with the help of @Jon_Shier, I found that setting the SWIFT_USE_INTEGRATED_DRIVER build setting to NO brings the incremental build time in Xcode 14.1 back down to ~23s suggesting that the issue I'm facing relates to the new integrated driver that was added to Xcode:

  • Swift driver, the component that orchestrates Swift front-end invocations, is now integrated into Xcode’s build system, allowing for more fine-grained dependencies to other build system tasks and explicit scheduling. (72440175)

Here's a screenshot where you can see the problematic step:

And the timing summary:

This is the raw invocation made by the 52s step:

SwiftDriver\ Compilation Global normal arm64 com.apple.xcode.tools.swift.compiler (in target 'Global' from project 'Global')
    cd /Users/liamnichols/Code/GitHub/cookpad/global-ios/Global
    builtin-Swift-Compilation -- /Applications/Xcode-14.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -module-name Global -Onone -enforce-exclusivity\=checked @/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Objects-normal/arm64/Global.SwiftFileList -DXCODE_1400 -DDEBUG -Xfrontend -warn-long-function-bodies\=500 -Xfrontend -warn-long-expression-type-checking\=500 -D COCOAPODS -D COCOAPODS -sdk /Applications/Xcode-14.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk -target arm64-apple-ios13.1-simulator -enable-bare-slash-regex -g -module-cache-path /Users/liamnichols/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -Xfrontend -serialize-debugging-options -profile-coverage-mapping -profile-generate -enable-testing -index-store-path /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Index.noindex/DataStore -swift-version 5 -I /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseABTesting -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseCore -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseCoreDiagnostics -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseCrashlytics -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseDynamicLinks -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseInAppMessaging -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseInstallations -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseMessaging -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebasePerformance -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseRemoteConfig -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/GoogleDataTransport -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/GoogleUtilities -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/ListItemFormatter -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/PromisesObjC -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/nanopb -F /Users/liamnichols/Code/GitHub/cookpad/global-ios/Pods/FirebaseAnalytics/Frameworks -F /Users/liamnichols/Code/GitHub/cookpad/global-ios/Pods/FreshchatSDK -F /Users/liamnichols/Code/GitHub/cookpad/global-ios/Pods/GoogleAppMeasurement/Frameworks -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/FirebaseAnalytics/AdIdSupport -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/FreshchatSDK -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/GoogleAppMeasurement/AdIdSupport -F /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/GoogleAppMeasurement/WithoutAdIdSupport -c -j10 -enable-batch-mode -incremental -output-file-map /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Objects-normal/arm64/Global-OutputFileMap.json -use-frontend-parseable-output -save-temps -no-color-diagnostics -serialize-diagnostics -emit-dependencies -emit-module -emit-module-path /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Objects-normal/arm64/Global.swiftmodule -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Global-generated-files.hmap -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Global-own-target-headers.hmap -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Global-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Global-project-headers.hmap -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseABTesting/FirebaseABTesting.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseCore/FirebaseCore.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseCoreDiagnostics/FirebaseCoreDiagnostics.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseCrashlytics/FirebaseCrashlytics.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseDynamicLinks/FirebaseDynamicLinks.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseInAppMessaging/FirebaseInAppMessaging.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseInstallations/FirebaseInstallations.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseMessaging/FirebaseMessaging.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebasePerformance/FirebasePerformance.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/FirebaseRemoteConfig/FirebaseRemoteConfig.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/GoogleDataTransport/GoogleDataTransport.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/GoogleUtilities/GoogleUtilities.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/ListItemFormatter/ListItemFormatter.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/PromisesObjC/FBLPromises.framework/Headers -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Products/Debug-iphonesimulator/nanopb/nanopb.framework/Headers -Xcc -I/Users/liamnichols/Code/GitHub/cookpad/global-ios/Pods/Headers/Public -Xcc -I/Users/liamnichols/Code/GitHub/cookpad/global-ios/Pods/Headers/Public/Firebase -Xcc -I/Users/liamnichols/Code/GitHub/cookpad/global-ios/Pods/Firebase/CoreOnly/Sources -Xcc -I/Sources/FBLPromises/include -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/DerivedSources-normal/arm64 -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/DerivedSources/arm64 -Xcc -I/Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/DerivedSources -Xcc -DDEBUG\=1 -Xcc -DCOCOAPODS\=1 -Xcc -DDEBUG\=1 -Xcc -DPB_FIELD_32BIT\=1 -Xcc -DPB_NO_PACKED_STRUCTS\=1 -Xcc -DPB_ENABLE_MALLOC\=1 -emit-objc-header -emit-objc-header-path /Users/liamnichols/Library/Developer/Xcode/DerivedData/Global-gxqyyvwrahgvtoabmdmcefksioce/Build/Intermediates.noindex/Global.build/Debug-iphonesimulator/Global.build/Objects-normal/arm64/Global-Swift.h -working-directory /Users/liamnichols/Code/GitHub/cookpad/global-ios/Global -experimental-emit-module-separately

In my best attempt to try and recompile only the Global (this is the main iOS app) target and not the dependencies, I deleted Build/Intermediates.noindex/Global.build, Products/Debug-iphonesimulator/Global.app and Products/Debug-iphonesimulator/Global.swiftmodule and re-built the project. This took a total of 68.4s. (less than the 75s incremental build) where the exact same problematic 52s invocation from above took only 0.1s

And the timing summary looks significantly different too:

I guess that one of my questions here is "what is the difference between 'SwiftCompile' and 'SwiftDriver Compilation'? I have no idea if the above is helpful, but I hope it might be.

@Slava_Pestov, @codafi: I attached logs and screenshots to FB11768802 and while I can't share the project source, neither do I know how to create a reproducer, I would be happy to jump on a video call to show you the issue if it helps.

10 Likes