My project consists of ~350 Swift files and ~40 cocoa pod dependencies.
As soon as the entire project was migrated to Swift 3, build times have been INCREDIBLY slow and took a little over 3 minutes to completely compile.
I've noticed that if I rebuild after not changing any files, it builds within a reasonable amount of time. However, if I add a new function, it takes the 3+ minutes.
Cocoapods does not seem to be causing the problem as it delays on Compiling Swift source files state.
I followed this to investigate:
Added the -Xfrontend -debug-time-function-bodies flag to my Other Swift Flags in my target's build settings
Build the project
Copied this into terminal and ran pbpaste | egrep '\.[0-9]ms' | sort -t "." -k 1 -n | tail -100
However, I didn't see anything of concern. The file that took the longest to compile was only 250ms. The next closest was 100ms, even if all 350 files took 250ms to compile, that would only be a total of 73 seconds which is way off from the 3+ minute builds I am seeing.
What could be causing these long compile times?
It was never as slow before updating to Xcode 8 and Swift 3.
Update 1:
I created a new project without running the Swift 3 conversion, imported my Swift 3 files, but the build time remains the same.
Update 2:
I've tried SWIFT_WHOLE_MODULE_OPTIMIZATION = YES, but as soon as you make changes to more than 1 file, the incremental build fails and it triggers a re-build which lasts for more than 4-5 minutes.
Update 3:
I've now re-written my entire code base from Swift 3 to Swift 2.3. It didn't make any difference, the problem lies with the Xcode 8 compiler.
Update 4:
I can confirm that unchecking these two
will alleviate the pain for a while, the Xcode 8 bug does seem to be tied to how it checks dependencies between files.
Update 5:
I've converted my code base to Swift 3 from Swift 2.3 since Xcode 8.2 beta requires it, the beta should include a fix for "Xcode will not rebuild an entire target when only small changes have occurred. (28892475)". Sad to say, they haven't fixed the bug and my compile times are exactly the same with Xcode 8.2 Beta.
Original post:
I don't have enough reputation to comment, but I still wanted to share some resources. I've been stuck in this misery for days, upgrading to Swift 3 has been a complete disaster.
I'm using this to track slow files, even though just like you, that's not my problem. Something else in xcode is taking literally 4 minutes to complete:
https://github.com/irskep/swift_compile_times_parser
https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode
I've also made sure I don't have any lazy vars or closures that swift doesn't like. Don't use the + operator when concatenating strings, etc.
see this.
I'll update this answer if I find anything, it's just about impossible to be productive with Swift 3 ATM.
I'm using Xcode 8.1 My issue was with Dictionary which uses Nil-Coalescing Operator
this is my code when it takes 10 minutes to build:
let params: [String:String] = [
"email": email ?? self.email,
"clave": password,
"tipo_documento": documentType?.rawValue ?? self.typeDocument.rawValue,
"documento": number ?? self.documentNumber,
"nombre": name ?? self.name,
"apellidos": lastName ?? self.lastName,
"fecha_nacimiento": birth?.parse() ?? self.birthDate.parse(),
"genero": genre?.rawValue ?? self.genre.rawValue,
"telefono_movil": cel ?? self.cel,
"direccion": address ?? self.address
]
I don't know why but it advertise me that the Dictionary take a long time to compile.
Then I change it to:
var params: [String:String] = [:]
params["email"] = email ?? self.email
params["clave"] = password
params["tipo_documento"] = documentType?.rawValue ?? self.typeDocument.rawValue
params["documento"] = number ?? self.documentNumber
params["nombre"] = name ?? self.name
params["apellidos"] = lastName ?? self.lastName
params["fecha_nacimiento"] = birth?.parse() ?? self.birthDate.parse()
params["genero"] = genre?.rawValue ?? self.genre.rawValue
params["telefono_movil"] = cel ?? self.cel
params["direccion"] = address ?? self.address
Hope it could help some of you.
Also string concatenation seems to be incredible slow in Swift3/XCode8:
item.text = item.text + " " + pickerText + " " + (attribute?.Prefix ?? "") + inputText + (attribute?.Suffix ?? "")
~ took 8-10 seconds to compile
item.text = "\(item.text) \(pickerText) \(attribute?.Prefix ?? "")\(inputText)\(attribute?.Suffix ?? "")"
~ took 1,6 seconds to compile
item.text = [item.text, " ", pickerText, " ", (attribute?.Prefix ?? ""), inputText, (attribute?.Suffix ?? "")].joined();
~ took 0,001 second to compile
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
Xcode version: 8.1 GM
To add choose your target, then go to Editor > Add Build Setting > Add User-Defined Setting, and add the above.
My clean build time dropped from 35 mins (Ahem, excuse me) to 8 mins with a project file count of 800.
Note: Tried this on Xcode 8.0 first, but didn't work.
I found a couple of coding styles that take a lot of time compiling in Swift (2.3, not tested on 3):
a += b
Should be
a = a + b
Also adding array together:
var a = [1,3,4]
var b = [5,6,7,8]
var c = [8,4,3,5]
var d = a + b + c
Should be
var a = [1,3,4]
var b = [5,6,7,8]
var c = [8,4,3,5]
var d : [Int] = []
d.appendContentsOf(a)
d.appendContentsOf(b)
d.appendContentsOf(c)
The last optimization took the compilation time for 1 method from 9800ms to 5.5ms...
I migrated a Swift 2x project of 17 files to Swift 3 and had 28 warnings and 55 errors across all files. Compile time was 4-5 minutes.
Disabling
Find Implicit Dependancies
in scheme and
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
made only minor improvements.
As I eventually cleared the warnings and errors in each file, the compile time reduced and is now in the seconds. The IDE is back behaving as it should - detecting errors in near real time and compiling quickly.
Firstly, it looks like the compiler is recompiling (or at least cross checking) every file with any error or warning - even if you haven't edited that file since the last compile.
Secondly, if there are too many dependant errors/warnings across files, the compiler bottlenecks and slows right down.
Whenever you face slow compilation issue, closly looks the the third party SDKs you included in your app and also try to find your coding techniques.
I face this issue twice in my app and I felt like harrassed by Swift 3 😡. Both the times reasons were different.
First time I found that I added a library in my app named AASignatureView. Since this lib was added, my compilation time increased like hell. It started taking near 12-15 Mins in running the app on simulator. The issue was resolved after I removed this lib from my code and added VMSignatureView and my compilation time went into normal state.
Second time I faced this issue after making a code of appending several Strings. Both of these below methods turned app's compilation time to hell
a = a + b
and
a += b
Then I changed my code to below way and the problem was solved.
a = "a\(strSometihng),\(strAnother)"
Concatenating several Strings also can cause increasing compiling times, for example in my case, my compilation times where very high because of this line:
let fecha = post.dia + " " + post.num_dia + " " + post.mes + " - " + post.hora
When i changed the code to this, it satart compiling in seconds:
var fecha = post.dia!
fecha = fecha + " "
fecha = fecha + post.num_dia!
fecha = fecha + " "
fecha = fecha + post.mes!
fecha = fecha + " - "
fecha = fecha + post.hora!
Related
Sometimes I have an issue with Xcode 6.0.1 where the error "SourceKitService Crashed Crashlog generated in ~/Library/Logs/DiagnosticReports" is popping up and all syntax highlighting is gone in Swift. How can I fix this?
Have this problem with Xcode 6.1 (release, not GM).
There a few "magic" solutions that works temporarily, but require a restart. There is quick fix that seems to hold (and does not require a complete restart).
Delete the content of: DerivedData/ModuleCache
(Full path: ~/Library/Developer/Xcode/DerivedData/ModuleCache)
This is a bug in Xcode and you cannot do much about it.
Update to Xcode 6.2 Beta 1 or higher if you want as the situation improved there. Still happening occasionally though.
Try emptying the ~/Library/Developer/Xcode/DerivedData folder. That should fix the problem.
My project started crashing SKS several times per minute recently, and none of the voodoo was working anymore.
My workaround—which is not going to last into later, more-complex phases—is to create a dummy project target within my current project (and select it as active). I add the file I'm working on to the dummy target, REMOVING the file from its proper targets temporarily.
Entails a lot of fiddling with target membership, but I am NOT nostalgic for the days of writing tons of code with a text editor.
I have faced such an issue. Source kit service was using 10 gb of usage. Swift process in activity monitor reaches over 6 GB usage. I was using following code:
var details : [String : Any] = ["1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":10, "11":11, "12":12, "13":13, "14":14, "15":15, "16":16]
I have changed code to following to solve this issue:
var details : [String : Any] = [:]
details["1"] = 1
details["2"] = 2
details["3"] = 3
details["4"] = 4
details["5"] = 5
details["6"] = 6
details["7"] = 7
details["8"] = 8
details["9"] = 9
details["10"] = 10
details["11"] = 11
details["12"] = 12
details["13"] = 13
details["14"] = 14
details["15"] = 15
details["16"] = 16
So im studying, and i need to run Ozcar debugger including on Mozart, i go to Oz menu and first i pick feed buffer, after that i pick Start Debugger, the compiler show me the next message:
local A B in
A = 5
B = 6
{Browse A+B}
end
% -------------------- accepted
\localSwitches
\switch +threadedqueries -verbose -expression -runwithdebugger
{Ozcar.open}
% -------------------- accepted
And then it suppose that a auxiliary windows should appears but nothing happens!!!! I need help pls!!!
Also the Oz emulator show me this:
%********************** Error: module manager *******************
%**
%** Could not link module
%**
%** Could not load functor at URL: x-oz://system/Ozcar.ozf
%**--------------------------------------------------------------
I think that the packagge of Ozcar is missing, where i can find it or how i can solve this???
You should use Mozart 1.4.0, the latest version of the 1.x Mozart branch.
Even if this question is more than 3 years old, the development of Mozart 2 is really slow and there still are a lot of features missing.
I've got the following problem:
I've written my first Swift App (for iOS7) and it worked fine.
After changing some minor detail (adding a string somewhere) it wouldn't compile anymore, even if I changed everything back how it was before.
There is no error message or anything like it, it says that it's building the project (Compiling Swift Source Files) but it's not progressing at all, even after hours of "building".
I've tried it with Xcode 6 b1 and b2 and with both it's the same: all the other projects are compiling without any problems, this one get's stuck.
Does anyone have a clue what might be the problem and how to solve it?
Debug the code manually works for me.
Finally I find the root cause of my problem is too many string concatenation in one line.
Bug code:
var string = string1 + string2 + string3 + string4 + string5 + string6 + string7 + string8
Fixed code:
var string = string1
string += string2
string += string3
string += string4
string += string5
string += string6
string += string7
string += string8
Xcode 6 Beta sometimes does not show any error but there will be some errors in your code. Because of that it does not compile.
Try to comment different parts of code and then try to compile. You have to find out the error manually.
I had this issue because I had some errors in my code but it was not showing.
Debug it manually. All the best.
Xcode 6 Beta 5 went into a tailspin for me immediately after I wrote out an expression to concatenate 3 strings and an NSDate object with the "+" operator.
Wouldn't compile and got stuck indexing.
Search your code for long string concats and remove for now. This is clearly a bug.
Several things you can try:
Clean the project: Product -> Clean
Go to Product try other options such as Analyze or Profile, see if it still stuck on build.
Restart xcode
Reboot System
Open system console and try to trace the problem.
Last but most importantly, really, because they are beta version, there will be some unexpected bugs. If it still cannot be solved, please report it to Apple and expect it to be fixed in beta 3.
Based on your comment, go to Terminal and type in: defaults write com.apple.dt.XCode IDEIndexDisable 1
This bug will relate to our project state and source code.
I rolled back some commits of my project, xcode succeeded indexing my project.
In my case, xcode failed to index, when my project has a declaration of large dictionary.
(I succeed indexing after removing it.)
I am using Ember.js to build a website for my company.
The problem I am having is that the initial load time of the page is around 10 seconds.
I cant give you the profiling data from chrome because I can't get them out of work.
However what I noticed when looking at them is that there is a function called "Get" which takes in total around 8.5 seconds. I realize this is probably just many uses of Ember.Get(), but still this is just the initial page load.
I don't know if this is normal or not but it's extremely unpleasant. Is there something I can do about this?
Thanks, Jason
try using a production release (the minified version of ember.js), it uses a significantly faster get.
Are you rendering some very large lists? If so look into using List View.
If you have a ton of fields being bound that don't ever change modify them to be unbound.
{{unbound someField}}
If you are having some weird issue where a template is taking a long time, yet you aren't sure which one it is, you can add some timestamp logging to the beginning of your templates to track down the culprit. At the bottom I whipped up a quick helper. In your template you could use it like so. It will print out a timestamp with that data point passed in.
{{logTime this}}
{{logTime name}}
Ember.Handlebars.helper('logTime', function(someField){
var d = new Date,
timestamp = d.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1") + "." + d.getMilliseconds();
console.log(timestamp + " - " + text);
return "";
});
I am facing a strange problem while I am debugging my program.
I developed a program that was working fine. Even when I made a minor change (added a hard-coded statement instead of putting watch for a variable and changing its value) in one part of the code, it was still working fine. But then I removed those changes, and from that point onward the program has been behaving very oddly. The variable that was hard-coded is still keeping the hard-coded value and not the one it should have according to flow.
I changed the line number 24 with the statement
return "shweta#2k7.com";
and again reverted the change to make it similar to the previous one, except that I deleted one blank line. So the total number of lines in the current code is 1 fewer than the previous code as shown below.
Now when I debug it, the control goes up to line no 26 even though there is nothing written there, and it returns the previous value "shweta#2k7.com" (which occurs nowhere in the code), instead of " ".
Current Code:
1 public string GetUserEmail(string userName)
2 {
3
4 if (!UserExists(userName)) return "";
5 try
6 {
7 DirectorySearcher search = new DirectorySearcher(_directoryEntry);
8 search.Filter = "(SAMAccountName=" + userName + ")";
9 search.PropertiesToLoad.Add("mail");
. .
. .
. .
19 }
21 catch
22 {
23 return ""; //"username#domain.com";
24 }
25 }
Previous Code:
1 public string GetUserEmail(string userName)
2 {
3 if (!UserExists(userName)) return "";
4 try
5 {
6 DirectorySearcher search = new DirectorySearcher(_directoryEntry);
7 search.Filter = "(SAMAccountName=" + userName + ")";
8 search.PropertiesToLoad.Add("mail");
. .
. .
. .
18 }
22 catch
23 {
24 return "username#domain.com"; //line number 24
25 }
26 }
After returning from this function, control passes to the Disassembly window where some assembly code is displayed.
Why is this happening?
Yes you are correct, It is running older version.
I am using Visual studio 2008. I did all such things like cleaning solution prior to Build/rebuild. But no gain.
I know the line inside catch executes only if try block fails, but here scenario is different(confusing too). It is not looking whether try failed or succeed, it is just looking line numbers. because when there is nothing in the line 26, then also control goes there.
I tried by removing blank line at 26, then control went to line 27(26 after removing blank line). you'll wonder by knowing that there was comment at line 27!!
However I have checkout the last safe version from SVN, and that worked fine.
But I'm also curious to know about this.
Shweta,
Line 24 is inside a catch statement, which is executed only if the try() fails. Is it possible that the try() succeeds, so Line 24 never executes?
On second thought, this smells like a case of not running the code that you think you're running: is it possible that your new source hasn't compiled properly, so you're still running the old version? If you're using an IDE (or a good makefile), you might try running clean, or manually deleting the object and executable files, and then rebuilding from scratch.
When you find the problem, please post a follow-up. I'm curious!
Good luck.