You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
F# solutions that contain a relatively large number of projects (e.g. 100) that have a relatively large number of project references (approx 50 on average) take an age to load, even with Lightweight Solution Load enabled.
On my machine, "Preparing solution" takes over 6 minutes (I killed VS after this so I don't know how long it takes in full). Furthermore each project load takes several seconds. This is in stark contrast to C# solutions of the same size and with the same number of project references, which takes under a minute to load completely.
This issue is not specific to VS 2017, as the same issue occurs in VS 2015 (and most likely 2013 too). I tried to use dotTrace to analyse where all the time is being spent, but 96% of it is in "Stack traces without user methods". I'm not sure whether this means I don't have symbols for some modules, or whether the majority of the time is spent in native code.
Repro steps
I have attached a script to reproduce this issue.
Download and extract the attached ZIP (see end of issue)
Run gen.fsx
Open dense/Dense.sln in Visual Studio. This will load a large F# solution.
Compare the load times to denseCSharp/Dense.sln.
Expected behavior
Similar performance to C#, as the projects contain no code or public interface to be analysed/type inferred.
Actual behavior
Painfully slow performance :(
Known workarounds
Use VS Code.
Related information
Provide any related information
Operating system: Windows 10
Branch: 2017 RC2
Editing Tools (e.g. Visual Studio Version): 2017 RC2
That's what I was using - there was a lot of Visual Studio stack traces but they amounted to <5% of the total time. I saw no FSharp stack traces so I assume they aren't being loaded for whatever reason.
Thanks - it looks like 99.5% of the time is being spent in FSharpProjectNode.ComputeSourcesAndFlags as a result of OnActiveProjectCfgChange.
This in turn invokes MSBuild to do a compile of the project (with actuallyBuild set to false - I'm not sure what this entails).
Do any of the F# developers mind shedding some light onto why this is necessary during startup, and whether there are any quick wins? This would drastically reduce load times for F# solutions. /cc @dsyme, @KevinRansom
@saul this is the same results I found when I was investigating huge pause after Ctrl+F5 on VFT solution, see the exact line and a big comment from @dsyme here #2046 (comment)
Thanks - I'd already read that but I still have a few questions for @dsyme
Why can't we use ComputeCompileItems to determine sources?
Why are the flags necessary to compute? Can't we use the same project file parsing logic instead of forking out to MSBuild (that does the same thing for us)?
If we really have to do it this way, can we at least show a message box whilst it's in progress? There's many situations where this locks up the UI thread for a significant amount of time (e.g. changing solution configuration).
@saul, I'm not sure what is ComputeCompileItems you are mentioning, one thing though is that the files and assembly references (I guess the two main things in fsproj files) can be wrapped around conditionals that need to be evaluated to give accurate result; I'm sure you know about this.
That being said, if we could have a "dumb" but quick way of getting this info (just with a xpath query?), even with inaccuracies, and catch-up in the background for the accurate results without locking the UI, I think this would really help a lot.
There's no need to use naive logic to get around this @smoothdeveloper. We already have access to everything to calculate the sources and flags ourselves without going via MSBuild. Not to mention MSBuild has already evaluated our project file so there's no need to guess at conditionals.
Here's my current understanding of what's happening:
At project load (and many other times such as changing solution configuration or adding files to the project), ComputeSourcesAndFlags is called.
This function invokes an MSBuild for the project with target Compile.
The Compile target is executed, which then executes the CoreCompile target which can be found in the Microsoft.FSharp.targets file.
This instantiates an Fsc (fsharp\FSharp.Build\Fsc.fs) task that calculates the compile flags and file sources, as defined in the project file.
MSBuild executes this Fsc task, which reflectively calls the Compile method on FSharpProjectNode (vsintegration\src\FSharp.ProjectSystem\Project.fs)
This Compile method then checks whether the compilation is as a result of ComputeSourcesAndFlags, in which case it simply stores the sources and flags and then bails without actually invoking FSC.
Here's my proposal for an alternative:
We are in full control of the sources array and the flags array - they are both calculated in FSharp.Build/Fsc.fs in ExecuteTool. There is no reason why we can't interrogate the BuildProject member in ComputeSourcesAndFlags: this.BuildProject.Targets["CoreCompile"].Tasks. We can then cast the ProjectTaskInstance to an Fsc instance and pull the sources and flags out then.
This completely removes the need to invoke a fake compilation with MSBuild, and we still have access to the evaluated values and so should function identically.
@vasily-kirichenko@saul Just to mention that's not my comment. The approach used dates from Visual Studio 2010, blame traces back to the initial import of the code into github
Not sure why "Compile" is used, it certainly looks wrong.
Compile is the target that C# and VB use for their design-time builds to find out the options and references to the compiler as well. The new project system aims to make this asynchronous and non-blocking. In the meantime, you might running a diagnostic build and looking at the timings of the various tasks and targets that run to see if you can optimize them at all.
Thanks @dsyme. Do you also have any idea as to why ComputeSourcesAndFlags is called twice for every project on configuration change (including at solution load)? There's a review comment that has the same concerns - this second call to ComputeSourcesAndFlags is the reason why "Preparing solution..." takes so long. I'd like to get that fix in for RTM if possible as it's a 50% solution load time win.
Also @Pilchie - have you any idea where this is done in the C# project system? C# projects seem to load instantly which is in stark contrast to the F# project system.
Thanks @dsyme. Do you also have any idea as to why ComputeSourcesAndFlags is called twice for every project on configuration change (including at solution load)?
@saul the C# invocations are in the closed source C++ code for csproj.dll and msvbprj.dll for most projects. Note that this is skipped for C#/VB with Lightweight solution load enabled though.
@davkean might be able point out where it happens in the new project system.
Opening Huge/Dense.sln in VS 2015 Update 3 takes 02:00 minutes to get to a fully working editor. After the "Preparing Solution" progress dialog closes, it's basically ready to use.
In Visual Studio 15.7.1 with the nightly tools - same machine, same solution:
00:36 minutes in, the Solution Explorer appears (and is populated). The 'Preparing Solution' dialog stays open.
08:16 minutes in, the 'Preparing Solution' dialog closes so I can now edit the source files. The UI is semi-responsive, syntax colourisation is not updating.
08:53 minutes in, the colourisation is updating in real-time as you'd expect.
I've got a feeling that we've regressed on the 'compute sources and flags' again, and that we're calling this too often on load again.
This is on an 8 core, 32GB RAM server with SSD - I dread to think what this is like on my dual core laptop.
So really, we've gone from 2 minutes in VS 2015, which is already really slow, to nearly 9 minutes in the latest tools 😢
@TIHan@davkean@davkean I'm curious about what the result of running the modified script for .NET SDK style projects looks. If it's a lot better, it may be worth modifying a converter project (e.g., @srivatsn's) for F# and working on it a bit so that we can recommend people convert.
The only recent change to the legacy F# project system was enabling design-time builds, and our measurement showed a slight decrease in project load times. So it would be strange if there was a regression here compared with a few months ago.
@cartermp So I've just tried @TIHan's updated generation script, and the Dense (100 project) solution loaded really quickly - in about 10 seconds to get to a responsive editor.
I could see that the projects were moving around/refreshing in the Solution Explorer (some projects had 'Dependencies' nodes, some didn't). After about 5 seconds, the UI completely locked up and 5 minutes later I still can't use it (it's 'Not Responding').
Activity
vasily-kirichenko commentedon Dec 26, 2016
Try to profile with dotTrace in its "Timeline" mode.
saul commentedon Dec 26, 2016
That's what I was using - there was a lot of Visual Studio stack traces but they amounted to <5% of the total time. I saw no FSharp stack traces so I assume they aren't being loaded for whatever reason.
vasily-kirichenko commentedon Dec 26, 2016
I can recommend to build VFT from current master, then run an experimental VS instance and profile it, you'll be able to see the sources in dotTrace.
saul commentedon Dec 26, 2016
Thanks - it looks like 99.5% of the time is being spent in FSharpProjectNode.ComputeSourcesAndFlags as a result of OnActiveProjectCfgChange.
This in turn invokes MSBuild to do a compile of the project (with
actuallyBuildset to false - I'm not sure what this entails).Do any of the F# developers mind shedding some light onto why this is necessary during startup, and whether there are any quick wins? This would drastically reduce load times for F# solutions. /cc @dsyme, @KevinRansom
vasily-kirichenko commentedon Dec 27, 2016
@saul this is the same results I found when I was investigating huge pause after Ctrl+F5 on VFT solution, see the exact line and a big comment from @dsyme here #2046 (comment)
saul commentedon Dec 27, 2016
Thanks - I'd already read that but I still have a few questions for @dsyme
ComputeCompileItemsto determine sources?smoothdeveloper commentedon Dec 27, 2016
@saul, I'm not sure what is ComputeCompileItems you are mentioning, one thing though is that the files and assembly references (I guess the two main things in fsproj files) can be wrapped around conditionals that need to be evaluated to give accurate result; I'm sure you know about this.
That being said, if we could have a "dumb" but quick way of getting this info (just with a xpath query?), even with inaccuracies, and catch-up in the background for the accurate results without locking the UI, I think this would really help a lot.
vasily-kirichenko commentedon Dec 27, 2016
Please, read the @dsyme comment https://github.com/Microsoft/visualfsharp/blob/master/vsintegration/src/FSharp.ProjectSystem.FSharp/Project.fs#L1350-L1360
saul commentedon Dec 27, 2016
There's no need to use naive logic to get around this @smoothdeveloper. We already have access to everything to calculate the sources and flags ourselves without going via MSBuild. Not to mention MSBuild has already evaluated our project file so there's no need to guess at conditionals.
Here's my current understanding of what's happening:
ComputeSourcesAndFlagsis called.Compile.Compiletarget is executed, which then executes the CoreCompile target which can be found in the Microsoft.FSharp.targets file.Here's my proposal for an alternative:
We are in full control of the sources array and the flags array - they are both calculated in FSharp.Build/Fsc.fs in
ExecuteTool. There is no reason why we can't interrogate the BuildProject member in ComputeSourcesAndFlags:this.BuildProject.Targets["CoreCompile"].Tasks. We can then cast the ProjectTaskInstance to an Fsc instance and pull the sources and flags out then.This completely removes the need to invoke a fake compilation with MSBuild, and we still have access to the evaluated values and so should function identically.
dsyme commentedon Dec 27, 2016
@vasily-kirichenko @saul Just to mention that's not my comment. The approach used dates from Visual Studio 2010, blame traces back to the initial import of the code into github
Not sure why "Compile" is used, it certainly looks wrong.
Pilchie commentedon Dec 27, 2016
Compileis the target that C# and VB use for their design-time builds to find out the options and references to the compiler as well. The new project system aims to make this asynchronous and non-blocking. In the meantime, you might running a diagnostic build and looking at the timings of the various tasks and targets that run to see if you can optimize them at all.dsyme commentedon Dec 27, 2016
@saul THe plan of attack you mention above sounds quite reasonable. Invoking MSBuild has always seemed spurious
saul commentedon Dec 27, 2016
Thanks @dsyme. Do you also have any idea as to why ComputeSourcesAndFlags is called twice for every project on configuration change (including at solution load)? There's a review comment that has the same concerns - this second call to ComputeSourcesAndFlags is the reason why "Preparing solution..." takes so long. I'd like to get that fix in for RTM if possible as it's a 50% solution load time win.
Also @Pilchie - have you any idea where this is done in the C# project system? C# projects seem to load instantly which is in stark contrast to the F# project system.
dsyme commentedon Dec 27, 2016
@saul
No, I don't, sorry
Pilchie commentedon Dec 27, 2016
@saul the C# invocations are in the closed source C++ code for csproj.dll and msvbprj.dll for most projects. Note that this is skipped for C#/VB with Lightweight solution load enabled though.
@davkean might be able point out where it happens in the new project system.
70 remaining items
saul commentedon May 13, 2018
Opening Huge/Dense.sln in VS 2015 Update 3 takes 02:00 minutes to get to a fully working editor. After the "Preparing Solution" progress dialog closes, it's basically ready to use.
In Visual Studio 15.7.1 with the nightly tools - same machine, same solution:
00:36 minutes in, the Solution Explorer appears (and is populated). The 'Preparing Solution' dialog stays open.
08:16 minutes in, the 'Preparing Solution' dialog closes so I can now edit the source files. The UI is semi-responsive, syntax colourisation is not updating.
08:53 minutes in, the colourisation is updating in real-time as you'd expect.
I've got a feeling that we've regressed on the 'compute sources and flags' again, and that we're calling this too often on load again.
This is on an 8 core, 32GB RAM server with SSD - I dread to think what this is like on my dual core laptop.
So really, we've gone from 2 minutes in VS 2015, which is already really slow, to nearly 9 minutes in the latest tools 😢
realvictorprm commentedon May 13, 2018
@saul do you have other projects where you could test whether the newest tools or the old ones are faster? Just curious
vasily-kirichenko commentedon May 13, 2018
@saul where can Huge/Dense.sln be found? gen.fsx does not generate such folder:
saul commentedon May 13, 2018
@vasily-kirichenko
visualfsharp\tests\projects\stress\huge\dense\Dense.slndavkean commentedon May 13, 2018
@saul Let's open a new issue to track this so that we don't lose track of it.
cartermp commentedon May 13, 2018
@TIHan @davkean @davkean I'm curious about what the result of running the modified script for .NET SDK style projects looks. If it's a lot better, it may be worth modifying a converter project (e.g., @srivatsn's) for F# and working on it a bit so that we can recommend people convert.
The only recent change to the legacy F# project system was enabling design-time builds, and our measurement showed a slight decrease in project load times. So it would be strange if there was a regression here compared with a few months ago.
saul commentedon May 13, 2018
@cartermp So I've just tried @TIHan's updated generation script, and the Dense (100 project) solution loaded really quickly - in about 10 seconds to get to a responsive editor.
I could see that the projects were moving around/refreshing in the Solution Explorer (some projects had 'Dependencies' nodes, some didn't). After about 5 seconds, the UI completely locked up and 5 minutes later I still can't use it (it's 'Not Responding').
davkean commentedon May 13, 2018
K, that will be the following:
Dependencies node issue is known and will because we can't catch the UI thread due to too much work done on it.
dsyme commentedon May 13, 2018
I'll reopen though let's just start a new issue for this please then close this. 20 pages of comments makes it hard to see the state of play :)
cartermp commentedon May 14, 2018
Created a newer and updated issue here so that 20 pages of comments don't get in the way of the current state of things.