When I build my project it takes lots of time to compile - visual-studio

I have a .Net Standard 2.0 project, when I try to build it using the command line (dotnet CLI) or VS (20017 v15.7.4) it took a long time to compile and CPU usage will rise to upper than 98%.
Is there any way for me to find out why that process is using too much CPU and where is CPU leak?

Have you cleaned your application? it seems your using Visual Studio which should have a Clean solution type button. I would recommend trying that, as well as restarting your computer to see if it speeds up the compile time.
Otherwise I would set up some timers in your code, and try to investigate which area of your code is making the application compile for an excess amount of time. Once you discover that you can try to improve the performance of that section.

Related

How can I make MSBuild use less CPU resources

This might be a bit of a weird question, but I'd like to make MSBuild slower.
At work I have the problem of having a rather slow project (compile time around 15 minutes) and currently only having one node on Jenkins that builds the project.
I am now trying to figure out how to use our own working machines as additional nodes if we so choose. My problem is now, that if I run MSBuild on the project, it uses every core of the CPU at 100%, which makes my system quite unusable during that time.
I'd like to throttle MSBuild a bit to not use every core to its fullest. Is that possible?
There is the switch "/maxcpucount[:numberOfProcessors]", but even if I use it I don't see any difference in CPU usage.
Can anybody help me here?
Screenshot of CPU usage with /maxcpucount:1
Okay. Finally found the correct phrase for searching and found https://developercommunity.visualstudio.com/idea/436208/limit-cpu-usage-of-visual-studio.html
Apparently there is now a switch in MSBuild, which sets the thread priority to low (-low). It still uses 100%, but the PC is at least usable. And through some environment variables it seems possible to limit the number of processors used, but that seems to be experimental still.
Also after much looking around I found this:
Pass /MP option to the compiler using MSBuild
Where the option /p:CL_MPCount=2 is used.

Wall clock analysis from Visual Studio Diagnostics Hub

The Performance and Diagnostics Hub in Visual Studio is an amazing feature. I use it for diagnosing Memory and high cpu issues while writing code. However, so far I am not able to figure out how to use this tool for troubleshooting low-cpu hang scenarios (or wall-clock analysis). Let's say my application takes long time on waiting a response back from a network or file I/O. Is there anyway of determining this from the Diagnostics windows in Visual Studio during a debugging sessions? I was hoping this analysis could be part of CPU Analysis section in there.
Like this blog here:
https://blogs.msdn.microsoft.com/devops/2014/02/28/new-cpu-usage-tool-in-the-performance-and-diagnostics-hub-in-visual-studio-2013/
The CPU Usage tool measures the CPU’s resources in terms of how much time each core in the CPU spends executing your code, it seems that it didn't provide the feature to resolve/collect the low-cpu hang issue.
Maybe you could think about using other tool like the PerfView or the suggestion of magicandre1981.
https://blogs.msdn.microsoft.com/vancem/2012/11/26/wall-clock-time-analysis-using-perfview/

Why isn't some resource maxed out to 100% during Visual Studio compile?

I'm compiling a large solution of about 100 C++ projects with Visual Studio. During compilation, neither Memory, CPU, Disk, nor Ethernet are utilizied to anywhere near 100% (according to the Task Manager Performance tab). CPU is often as low as 25% and Memory Disk utilization seems to be as low as 5-10%.
So if no resource is utilized at 100%, what's the bottleneck? What's limiting my compile speed? I was honestly expecting it to be CPU. But it seems that it's not.
Am I perhaps measuring incorrectly? What should I expect to be the limiting resource when compiling? How can I speed things up? If there's something else that is the limitation (like RAM but as I/O via a cache or something) then what's the right tool/method to measure the bottleneck?
Additional Info: I'm certainly using maximum number of parallel projects to build = 8. Also multi-processor compilation is enabled for all the Visual C++ projects. My machine has 8 logical processors. So I really think that I'm not just maxing out one core. That would present itself as 12.5% usage on my machine, (and I see that often with single-threaded applications.)
well memory wise maybe your application don't use as much memory.
and as for the CPU usage, your program might be working on one thread, or to be more specific, on one single core of your CPU;
so if you have a quad core CPU, your application won't use anything above 25%.
as for the internet usage, i think that the task manager shows you computer's Ethernet capability, so maybe you have an internet speed of 10 Mb/s, but your Ethernet is capable of 50 Mb/s.
this is a link that i just looked up :https://askleo.com/why_wont_my_program_use_more_than_25_of_the_cpu/
great question.
Just setting the compilation to run all projects in parallel you just get the same result as #VasiliyGalkin, too much work for your setup.
But due to the way VS compiles each project you need a certain overlap so limit the number of parallel projects to 2-3 depending on the actual PC you run it on. If your PC is a monster with 16+ cores you might be able to go 1-2 up. You might be happy about the result or find that it doesn't fully use your CPU due to other limits in VS.
This article gives an in depth analysis of why its slow, the conclusion is that you need to set up your compilation to fit VS idea of the world.
A brief of the article
I would guess your setup is something like
Multiprocess compilation off
Giving you the following performance
Setting it to on and setting
enable minimal rebuild off
Gives you
Still for one project because your compilation times for your units is like this
Due to different compilation flags / precompiled headers see article for more. Fixing it gives you something like
and the 3 progression after each other
Now add max project 2 or 3 to use all capacity.
Ideally VS should have offered an option of using X threads so the problem would mostly go away as no more threads are started than usable and it would just pick the next task from the next project when there are free resources.
Memory is very unlikely to become a bottleneck for the compilation. Normally it's CPU-intensive process. The fact that your CPU is used for 25% instead of 100% may indicate that your projects are compiled sequentially using 1 core out of 4.
Try to check the "maximum number of parallel builds" in Visual Studio menu Options -> Projects and Solutions -> Build and Run.
You may find the screenshots attached to my recent question related to similar topic, but opposite problem - too much going in parallel instead of too little :)

How to reduce the size of Qt build?

I'm trying to build Qt with visual studio (2010), but the build has so far taken up over 16GB of my tiny hard drive. I've already uninstalled practically every program I have.
Is there any way I can compile qt without it hogging so much space, yet still get every feature? And once the build completes, will the unrequired files clear up, or do I have to do that manually? How big will the build be (as said earlier, I've already reached 16+ GB)?
I'm new to this, so please speak in layman's terms. Thanks.
Start with 40-50GB of free space. The build generates a lot of temporary files which you can clean later manually.
If that is too much for your computer, get an external harddisk. 1000GB should be less than $100.
You can reduce it's size by avoiding Qt-WebKit,etc(if you want). Check this link

How can I determine why a build runs slowly in Visual Studio 2005?

I wanted to know if it is possible to know why a Visual Studio 2005 (MSBuild) build is taking a long time to build a project.
Suddenly we are getting 7-minute build times on some computers, while others take less, such as 4 minutes.
So I think I need to identify changes that were made to the project and are causing a longer build time.
Any ideas on how I can do that?
Take a look at MSBuild Profiler to analyze where the slow down is. Based on that information, dig into what each task is doing and factor in the things that Chris mentions in his answer.
Is it a C++ project? I had the same problem when I moved my project from Visual Studio 6.0. Turning off the Code Optimization did save a lot of time. It was almost impossible to work with activated Optimization.
It re-evaluates the references on every build. If any of your references are on network drives that could be slowing it up.
Some computers are naturally going to perform builds faster than others.. This is, in part, a function of processor, ram, and HD speeds.
Regarding why you see 7 minute build times there could be any number of reasons. Amount of code in project(s). Number of projects in solution. Amount of post / pre build steps. Speed of network in downloading anything from source control it needs. Number of other processes running on your computers. Amount of RAM and other resources available to perform the builds..
You get the idea.

Resources