Xcode 9.2 is re-indexing from scratch each time I open it, even if nothing changed - xcode

I have a project (big project), that takes about 30 minutes to be indexed by Xcode. Xcode consumes 100% of my CPU for 30mn.
OK why not, that sounds a bit rude to use 100% of the CPU for a background task, but why not.
Now, if after 30 minutes, I quit Xcode, and re-open it, without touching a single file of my project, it starts again to index for 30 minutes.
Is this the intended behaviour? Is there a way to fix it? I don't want to turn off inedxing, I tried it, and code completion is HS.

Try adding this flag to your build settings.
Xfrontend -warn-long-expression-type-checking=400
It will cause warning where the compiler take a long time to deduce a complex expression.
This may cause a build error which will go away after you find the slow expressions and then remove the build flag.

Related

Xcode always builds all my targets in the current scheme, even without any change

With Xcode 8.1 I see this phenomenon that even if I didn't change something on triggering Run Xcode goes through all targets of the selected schema and builds them (which is a mix of mostly C++ and some Obj-C code). All images are processed, all scripts run etc.
However, in the build log I see that the cpp files are not really compiled, they are just listed, so the overall build time is not that of a real build. Still, even with a few seconds on each target I get a delay of 10+ seconds (and a lot of file operations) before the debug session starts actually, which is a pain if you need to restart the debugging session frequently.
Is there any solution to avoid this "pseudo build"?

Stopping xcode from indexing

I've been working with xCode 4.5.2, and have noticed that if you are indexing, you need to stop everything and let it do it's job, or else you'll get bogged down. It's become a bit of a problem, as the project is a large one, and indexing has been taking a long time to do, and it will do it constantly. One instance was it indexed the entire project, after I worked a little bit on the project it started to re-index almost 75% of the project. I checked with source control, and there had been no changes to the project in the amount of time I worked on it.
Is there any way to stop the indexing entirely, or reduce the amount of times it indexes? Are there any downsides of turning off indexing? I had read in previous questions where it was said it prevented auto-complete and searching through the project.
Just run this command in the terminal to turn off Indexing:
defaults write com.apple.dt.XCode IDEIndexDisable 1
To turn it back on, run this:
defaults write com.apple.dt.XCode IDEIndexDisable 0
(Note: Apparently you need to delete this key in order for the change to take affect, however, I used simply the above command and it worked fine. So if doing the above doesn't work, try deleting the key)
EDIT
Sorry, missed part of the question. Yes, it will make it so searching does not work as fast. Perhaps auto-complete will get disabled. Indexing is what allows Xcode to quickly remember what you have done. Turning it off will make it slightly harder to work with, but it improves loading time.
Whatever is your reason to want this (mine is "An internal error occurred. Editing functionality may be limited") for Xcode 10.1:
defaults write com.apple.dt.Xcode IDEIndexDisable -bool true
Close Xcode, run this, open Xcode.
If you are working on a large project and generate the xcodeproj with cmake, you will get into problems when you add large binaries into it. If cmake doesn't recognize the extension it tags them as 'sourcecode' by default!
... and those binaries will then be indexed by xcode, meaning your machine is constantly indexing ( and start from scratch each time you regenerate the workspace ). Also find-in-files won't work (it just hangs).
One easy solution is to tag your binaries and tell xcode to ignore them, e.g. like this ( cmake 3.2 and higher, otherwise XCODE_EXPLICIT_FILE_TYPE isn't supported ) :
# fill cmake-variable with some files
file(GLOB MYGAME_BINARIES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "binaries/*")
# tag them as "not-sourcecode" ( maybe there is sth better than 'compiled', but it worked for my purpose)
set_source_files_properties( ${MYGAME_BINARIES} PROPERTIES XCODE_EXPLICIT_FILE_TYPE "compiled" )

Xcode 4.3.2 and 100% CPU constantly in the idle time

My Xcode started to behave very heavily from yesterday when working on medium size project (around 200 source files). Project compiles correctly and runs in both simulator and device. I do not use any 3rd party libraries, except few widely used includes (like JSON or facebook ios sdk).
It constantly uses CPU(s) at full speed, even if it is in idle state (no indexing, no compiling, no editing). The usage of RAM is relatively normal (300-50MB).
My machine uses: Core 2 Duo 3.04Ghz CPU, 8GB of RAM and Vertex OCZ 3 SSD drive.
I have tried every suggested solution found at stackoverflow:
Cleaned project
Cleaned Derived Data in Organizer
Cleaned repositories in Organizer
Cleaned xcodeproject bundle from workspace and userdata files as suggested here: https://stackoverflow.com/a/8165886/229229 (it is helping just for a moment and starts again after minute or so).
Restarted Xcode many times (with the same effect as in 4).
Disabled "Live issues"
even Reinstalled Xcode
Nothing helps. In most cases, Xcode indexes the project for a moment, then comes back to the normal performance, but after a while becomes unusable again. CPU jumps back to 95-100% for both cores, intelligence hangs, etc...
I am attaching screenshots of how the Xcode processes are seen by the Instruments:
UPDATE:
After a moment of hope that I solved the problem by moving around few
#import "header.h"
statements from headers to the implementation files and exchanging them with forward declarations ... the problem came back again after a while.
I am adding the console log.
The strange thing is that the logs related to Xcode show up after I quit it, not during the run itsef.
Console logs:
5/11/12 9:27:03.777 AM [0x0-0x45045].com.apple.dt.Xcode: com.apple.dt.instruments.backgroundinstruments: Already loaded
5/11/12 9:27:05.571 AM Xcode: Performance: Please update this scripting addition to supply a value for ThreadSafe for each event handler: "/Library/ScriptingAdditions/SIMBL.osax"
5/11/12 9:27:58.168 AM Xcode: ERROR: Failed to create an alert for ID "enabled" based on defaults: 1
What stopped my nightmare was:
Change Always Search User Path to NO in Project build settings (bolded).
Remove -objC flag Other Linker Flags (also bolded setting).
And then delete Derived Data and wait until Xcode reindexes.
I am not sure which of them helped bacause I changed both of them at the same time and I am so behind my schedule I have no time to test it. I will improve this answer when I reproduce the bug and solution in spare time.
However, there is a hint:
*Rethink and recheck your project / targets build settings.*
It is highly probable that this strange behavior may be caused by some unfortunate combination of build settings.
All my projects does this from time to time. I can shut down X-code and start it up again and it'll run fine for a while, then go back to using 200% CPU time (two cores fully loaded).
My solution is to use AppCode as my primary IDE (has the added benefit of being a much better IDE, but that's another story). I only start XCode when I need to edit storyboards and shut it down when I'm done - usually that keeps the problem at bay.
AppCode runs off the same project files/structure has better and faster indexing and never runs into this issue, so I can't see how this can be a settings/configuration problem - it must be a bug in XCode. Hence, I would not waste time changing your code structure as it will most likely only delay the problem, not fix it.
No way to know if the OP actually had a different root cause, but for me it appears to have been an Xcode glitch with git. Adding / committing my current changes solved my problem. Here is the complete scenario and what I did to get it fixed:
Environment:
Xcode Version 5.1.1 (5B1008)
Macbook Pro OS X 10.9.2
2 GHz Intel Core i7, 8GB RAM
I noticed Xcode was starting to eat 200% of my CPU constantly.
Not sure exactly when it started, but Xcode did freeze up on trying to make a snapshot (400% CPU usage for several minutes until I force-quitted Xcode)
After reopening, I noticed Xcode was still stuck indefinitely at 200% CPU usage.
Closing all projects did not work.
Deleting all derived data and restarting did not work.
Uninstalling Xcode and reinstalling at first held promise, but once I re-opened my main project, the CPU returned to a constant 200% CPU usage. (after indexing finished)
Closing the troubled project did not help. Xcode was now stuck again in forever-kill-200%-of-CPU land.
After looking around Stack Overflow, multiple people alluded to git being an issue.
I have a slightly complicated git repo (has a submodule repo and a subproject within the main Xcode project).
I had pending changes in both the main repo and submodule portion of the repo.
I closed Xcode and git added & committed all my current changes.
Reopen Xcode and VIOLA! No more CPU being killed. Back down to 0.0% idle usage.
Xcode 5.1.x seems to struggle with git in other ways for me too (sometimes does not pick up changes in the GUI, etc.) so perhaps there are Xcode git integration bugs.
It looks like it's spending its time parsing ObjC included in the PCH.
How many PCHs must clang generate? In your project, that would be one for C, one for ObjC, one for C++, one for ObjC++ for each dialect/lang used in your project and any dependent targets. That is -- if you have a dependent library included in your app's PCH and you are hacking on that library, all code sense in the app target must be invalidated and parsed again each time you alter a header included by your pch. And if your target compiles a C file, it will need a PCH for C. If it needs one for ObjC, it will need to generate one for ObjC.
How often do you alter the PCH (or anything included by it)?
Remove includes from the PCH. It's not unusual to see every linked framework included in a PCH (avoid doing this!).
If you change your build or preprocessor settings, it may need to rebuild the code sense index for the target(s) entirely each time.
Have you tried disabling live issues?
On my projects (all of them) it was the autocompletion/intellisense. When I changed one line of code in my .h files, it went haywire, +100% CPU usage (more than one core).
I just disabled it, now I have to think a bit more for myself (like I used to do on windows) and it works great at low CPU usage.
i used to encounter this problem.it is caused by git.Although i don't know the git very well.i removed the file named .git in the project directory and it turned to normal.by the way,the .git is hidden.

For VS2010 (C++) what causes the long delay between clicking on "Build" and when the build actually starts?

I have a simple one-project solution in C++. From the IDE I click on Build Solution and it takes 40 seconds before anything happens. Then 17 seconds to actually do the compiling and linking. If I click Build Solution again, there is another 40 second delay. devenv.exe is busy doing something as it is using 13% of my total CPU during this time.
If I call msbuild directly, it starts immediately. And it doesn't recompile unless it is truly out of date. So it doesn't seem to be a problem with msbuild at all.
I have Googled and chased down lots of articles, but most of them talk about why msbuild is slow or failing, not why the IDE is slow to call msbuild. I've even got an external tool setup using msbuild and it starts immediately. BTW, that tool is based on this:
http://www.hanselman.com/blog/HackParallelMSBuildsFromWithinTheVisualStudioIDE.aspx
I have checked for missing files using the devenv.exe.config change and I do get items like:
devenv.exe Information: 0 :
Project 'C:\Users\...\XFPMon\XFPMon.vcxproj' not up to date because 2 build outputs were missing.
devenv.exe Information: 0 :
up to date is missing: 'C:\WINDOWS\TEMP\AEXAM\AEX7C29.TMP'
devenv.exe Information: 0 :
up to date is missing: 'C:\WINDOWS\TEMP\AEXAM\AEX7C28.TMP'
The change to devenv.exe.config was to insert these:
<system.diagnostics>
<switches>
<add name="CPS" value="4" />
</switches>
</system.diagnostics>
and then use DbgView to trace the output during the build. I cannot imagine why devenv.exe would think that TEMP files would be saved between builds.
I have even deleted the Debug and Release directories and compiled from scratch. Still the 40 second delay.
If I do a Rebuild Solution, another 40 second delay.
But if I do a Clean Solution, it runs instantly!
Does anybody have a clue as to what is causing the delay?
Thanks!
EDIT:
Further information. I have 8 cores, 12 GB RAM, and a 256 GB SSD, so this little machine has the raw horsepower.
When devenv.exe is in the 40 second delay period, it is drawing a total of 13% of the CPU. When the compilation starts, it drops to less than 1%. The memory usage changes very little. It starts at 458.2MB, rises to 459.9MB during the 40 second delay, and then jumps to 463.1MB immediately after the compilation (if any) finishes.
Well, I found the problem. An Addin was taking exponential time to process the .rc and .rc2 files. The Addin was put in many months ago and did not start showing this problem until the size of .rc file grew enough to cause the (poorly-designed) regex to run very slowly.
Worse, I wrote the Addin! And have been using it on several machines for about a year with no problems. Previous versions of the Addin were written in C++ using PCRE regular expressions and never had a problem (even after 5 years of use). But this was a rewrite using C# and .NET Regex, which apparently behaves differently.
I fixed the problem by rewriting the code to avoid the need for some of the backtracking. Simple enough to do, but irritating that it was necessary for C# Regex.
The key to discovering the problem was to start devenv.exe with the /resetaddin option. With this, a build starts immediately. Then it was just a matter of figuring out which addin. I just hadn't done this as I hadn't changed addins for months.
This problem showed up when the .rc file was as small as 12K. I have tested the new version on a 262K .rc file and it runs in 123 ms.
Sigh.

When and why should I clean the build in XCode

Every once in awhile, the solution to an aggravating problem in XCode is to hit Product → Clean, and this seems to clear some cache and problems disappear.
But what is it actually doing? And more importantly, WHEN should I be doing this? It seems to be necessary more often when dealing with Core Data, but I haven't really been tracking it.
As a side question, WHY is this necessary? XCode seems to do a lot of stuff in the background (autosave, autocompile, etc). Why doesn't this also just happen in the background?
It's because there are a lot difference when you are working with a very very big project with a lot of files and objects. Imagine that you need an hour to recompile a entire project, so you will think before do this. But in our world, this is a fast task.
XCode use the make program. So, it compile only what was changed.
I can list same cases you need do this:
Always you will create a App for App Store. This safety thing to do.
Always you use the XCode Snapshot. I have bad time when I restore a project and build the app. XCode used old compiled files and a lot of time was lost to search it.
Maybe when you restore a old code with git. Is the same idea of the Snapshot
When you delete or rename a file in project. It don't delete the compiled file, so the program can work, but if you recompile, will see the errors.
When you see that sometime the build have a strange behavior. Or only to have certain that XCode use only your newer files.
I don't remember exactly but i have seen the build use old #defines. Rebuilding can make you more safe about your program. But don't need do this all time.
I am almost certain that XCode loses track of things and sometimes it doesn't recompile (or link, not sure) everything is needed. I have to resort to clean and build all most often than it should. Maybe it's just me, but I doubt it... XCode is the IDE with most bugs I have worked with

Resources