Xcode 8 recompiles every file every build

Whenever I make a change to a file, like add a new property or create a new class, Xcode recompiles every single file on a build, and it takes quite some time. I've got this happening on the GM on two different computers (one running 10.12 one running 10.11).


I've tried:

  • copying every file to a new Xcode project created in Xcode 8 GM
  • removing every "Other swift flag" flag
  • removing all third party libraries
  • comparing my project's build settings to a new project's build settings
  • remove all test targets leaving just the one target I need
  • removing all ObjC code
  • removing all ObjC related flags


Really the kicker is that moving all my code to a new project shows that it's something in my code.

Any ideas? My productivity is way down having to wait ~ 1.5 minutes for every build / auto complete / syntax highlighting to work. And yes, I've cleared derived data 🙂



UPDATE:

One more peice of information, I found this information https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160411/001693.html


which tells us about a "-driver-show-incremental" flag, which will cause queued dependancies to be listed in the build log. Sure enough I see what I think is every single swift file I have listed in the output. Trying to figure out if there's a way to make sense of what the dependancies are...


Output is something like:


...

Queuing Form.swift because of dependencies discovered later

Queuing SignInViewController.swift because of dependencies discovered later

Queuing EditProfileViewController.swift because of dependencies discovered later

Queuing ChangePasswordViewController.swift because of dependencies discovered later

Queuing JoinViewController.swift because of dependencies discovered later

...

Just wondering, what is everyone running?

I'm on Xcode 8 and El Capitan

I have the same issue on Sierra.

Our project dosn't containing any swift code, but we also encounter this problem. Is there any ways to see what causes project to be full rebuilt, something like

-driver-show-incremental for Objective-C projects.

This issue become more worse and worse after upgrade to Xcode 8 and Swift 2.3. Now everytime need full build even just add a comment inside a function!!

I've solved it in my project.


Go into your target's build settings and change the C Language Dialect to Compiler Default


Sources:

1. http://stackoverflow.com/questions/39588223/xcode-8-recompiling-complete-code-everytime/39874030#39874030(my bounty!)

2. http://stackoverflow.com/questions/36438919/xcode-7-3-library-project-compiles-every-time

3. https://forums.developer.apple.com/thread/44406



EDIT: I was wrong. Back to compiling everything again. I can't work like this.

This didn't work for me – as soon as I made a change to the code it started recompiling from scratch again.

Reported

Radar: 28645028

I couldnt find the Dialect flag in Xcode?

Sorry for dragging my feet, I need to take the time to make an example project, but I haven't done so yet.


To add some more information on what I think may be happening in my current project I can't share...


After reading https://github.com/apple/swift/blob/master/docs/DependencyAnalysis.rst I'm scared that things are actually working as expected. The line "If there's not enough context to decide, the compiler has to go with the conservative choice and record it as cascading." I think is the heart of the problem. All of my coworkers projects (about 5 I've checked with) have this issue. The projects that are relativley new and small seem to not have a problem, simply becuase there's not a lot of files so recompiling every time doesn't manfest itself as a noticiable issue. But for the projects that are of any size or further along in development, we're hitting 30 seconds - 3 minutes incremental builds.


Here's an example of how I think the dependnecys get out of hand. I make a change in my root view controller, which holds my tab bar controller, which holds my 5 main feature controllers, which hold their detail controllers, etc. The change in the root view controller is, I *think*, a non cascading change, but the compiler can't figure out if it's non cascading or not, so it's marked as cascading. This means that it needs to recompile the tab bar, feature controllers, detail controllers, etc, because it just can't know for sure that a non cascading change has been made to any of those. Then you get into it needing to recompile all those controller's dependacnies, and now you have a 1 minute incrementail build even though you may have just added a private function that nobody even uses to a controller.


It's hard to notice this issue when you're working on a toy project, but once you're working on a "real" scale application it becomes very apparent. I'm scared that there's a very small amount of developers out there making "real" sized apps in 100% swift at the moment, so it's a realitivly quiet problem. A lot of established apps are just adding newer features in swift, so they don't have the issue yet, but as we start moving towards more swift code in older projects, or more swift first apps, this will become a much more real issue.


Sorry for rambling a bit, just wanted to get my thoughts out!

Xcode8 and Sierra.

It's horrible.

Before finding this thread I started a discussion on Stackoverflow.

One guy seems to be on to something by changing the optimization flag of your code.

His and my project seem to compile faster when you turn on Whole Module Optimization.

Quite counter intuitive, but I can reproduce it.


Check it out here:

http://stackoverflow.com/questions/39879979/xcode-8-very-slow-swift-compiling/39949519#39949519



EDIT:

It appears that the answer I was referring to has been deleted, sorry.

Your milage may vary, but I seem to have had success with this by getting rid of a lot of the imports in my prefix header. (I tried to get rid of it completely but it's too daunting of a task right now.)


Peeking into the ModuleCache directory, it seemed like Xcode was coming up with way too many configurations where it needed to create a new ModuleCache entryfor all the modules (and precompiled prefix headers), so from there I started trimming down the imports in my prefix header for the mean time (since I couldn't just delete the prefix header entirely), which seems to have alleviated the problem.


I wrote up all the details here:

http://stackoverflow.com/questions/39588223/xcode-8-recompiling-complete-code-everytime/39976395#39976395


Hopefully this helps someone out there.

Bump.


Been over a month and nothing... anyone able to find a fix? Working like this is miserable. The scheme trick ocasionally works but only for a couple of builds.

This is driving us cray... We are a 4 member team and we spent almost 80% of our time waiting for the xcode to compile.

This has to be the worst bug in xcode history.

… we spent almost 80% of our time waiting for the xcode to compile.

Yowsers! Presumably you filed a bug about this. What’s the number?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I also have this problem and it's driving me nuts.

From a reddit discussion somebody tipped me about this obscure Xcode 8 defaults setting:

defaults write com.apple.dt.Xcode ExplainWhyBuildCommandsAreRun -bool true


Paste in Terminal and restart Xcode.

The name is self-explainatory - it generates debug output when building, explaining why.


Then when building you can check "Build target XXX" -> "Compile Swift source files" in the Report Navigator

The issue seems to be "(running because command line arguments are different from the last time)"


This hasn't solved my problem, but at least is pointing somewhere.


My rdar is

28501724 marked as a duplicate of 28292226

Thanks IvanD,


I did try your suggestion and I am also getting the "(running because command line arguments are different from the last time)" message when the problem occurs [I can get Xcode to recompile the entire project by just touching a single swift file without making any changes].


I did capture the different arguments and have filed a bug report (28799303).

This is a great bit of information. I ran


defaults write com.apple.dt.Xcode ExplainWhyBuildCommandsAreRun -bool true


Then built my app twice (making sure the second build wasn't incremental), and I extracted the two argument list.


Ran this command:


wdiff arg1.txt arg2.txt | colordiff


Here's what I get:


[-Internal-all-target-headers.hmap-] {+Internal-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /DerivedData/App/Build/Intermediates/App.build/all-product-headers.yaml+}


So it seems that between builds a combination of the following params gets added/deleted:


Internal-all-target-headers.hmap
Internal-all-non-framework-target-headers.hmap
-Xcc -ivfsoverlay
-Xcc ../DerivedData/App/Build/Intermediates/App.build/all-product-headers.yaml


I'm not too sure what those arguments are, maybe someone at Apple can clarify this for us?

28501724 marked as a duplicate of 28292226

Thank you for both filing a bug and posting the bug number here.

The bug yours was duplicated to (r. 28292226) is being actively investigated. There’s no fix in the current (Xcode 8.1 beta 3, build 8T47) but please check back in when we release anything later than that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

My apologies to everyone experiencing this problem, we are actively trying to get to the bottom of this issue.


If anyone experiencing this problem is in a position where they can share their entire project, as well as a video of experiencing the bug (ideally multiple times) via a screen recording, that would be immensely valuable to us.


In the meantime, we believe that setting:


HEADERMAP_USES_VFS = YES


to true in your project (or for all your targets) may be an effective workaround for many people. This is not guaranteed to work (which is the reason it isn't already on by default), but it should work for most projects.

Mine (28645028) has been marked as a dupe of 28292226


And yes, currently still using

HEADERMAP_USES_VFS = YES

It's made a slight difference

And Xcode8 crash frequently, I don't know whether it related to this bug. BTW, Xcode recompiling all source files every time and it make The storage space of Macintosh HD comsume very fast


Update:

And when I reboot my mac pro, the project compiling very fast. As I use for a period of time, Xcode compiling files become slow and slow and crash frequently.


SO, I GUESS the bug that Xcode recompiling all source files if cause by "DerivedData“ cache in mac.

Thank you ddunbar!

This workaround seems to be working for us so our team is now writing code more than waiting 🙂

Hi ddunbar,


Where we have to set to true this setting? I can't find it in the build settings of my project


Thanks

Where is this setting ?

Xcode 8 recompiles every file every build
 
 
Q