Skip to content

Unacceptably slow solution load times #2107

Closed

Description

@saul

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.

  1. Download and extract the attached ZIP (see end of issue)
  2. Run gen.fsx
  3. Open dense/Dense.sln in Visual Studio. This will load a large F# solution.
  4. 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
  • Links to performance testing scripts: Perf.zip

Activity

  1. vasily-kirichenko commented on Dec 26, 2016

    @vasily-kirichenko
    Contributor

    Try to profile with dotTrace in its "Timeline" mode.

  2. saul commented on Dec 26, 2016

    @saul
    ContributorAuthor

    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.

  3. vasily-kirichenko commented on Dec 26, 2016

    @vasily-kirichenko
    Contributor

    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.

  4. saul commented on Dec 26, 2016

    @saul
    ContributorAuthor

    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

    sketch 19

  5. vasily-kirichenko commented on Dec 27, 2016

    @vasily-kirichenko
    Contributor

    @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)

  6. saul commented on Dec 27, 2016

    @saul
    ContributorAuthor

    Thanks - I'd already read that but I still have a few questions for @dsyme

    1. Why can't we use ComputeCompileItems to determine sources?
    2. 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)?
    3. 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).
  7. smoothdeveloper commented on Dec 27, 2016

    @smoothdeveloper
    Contributor

    @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.

  8. saul commented on Dec 27, 2016

    @saul
    ContributorAuthor

    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:

    1. At project load (and many other times such as changing solution configuration or adding files to the project), ComputeSourcesAndFlags is called.
    2. This function invokes an MSBuild for the project with target Compile.
    3. The Compile target is executed, which then executes the CoreCompile target which can be found in the Microsoft.FSharp.targets file.
    4. This instantiates an Fsc (fsharp\FSharp.Build\Fsc.fs) task that calculates the compile flags and file sources, as defined in the project file.
    5. MSBuild executes this Fsc task, which reflectively calls the Compile method on FSharpProjectNode (vsintegration\src\FSharp.ProjectSystem\Project.fs)
    6. 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.

  9. dsyme commented on Dec 27, 2016

    @dsyme
    Contributor

    @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.

  10. Pilchie commented on Dec 27, 2016

    @Pilchie
    Member

    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.

  11. dsyme commented on Dec 27, 2016

    @dsyme
    Contributor

    @saul THe plan of attack you mention above sounds quite reasonable. Invoking MSBuild has always seemed spurious

  12. saul commented on Dec 27, 2016

    @saul
    ContributorAuthor

    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.

  13. dsyme commented on Dec 27, 2016

    @dsyme
    Contributor

    @saul

    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)?

    No, I don't, sorry

  14. Pilchie commented on Dec 27, 2016

    @Pilchie
    Member

    @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.

  15. 70 remaining items

  16. saul commented on May 13, 2018

    @saul
    ContributorAuthor

    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 😢

  17. realvictorprm commented on May 13, 2018

    @realvictorprm
    Contributor

    @saul do you have other projects where you could test whether the newest tools or the old ones are faster? Just curious

  18. vasily-kirichenko commented on May 13, 2018

    @vasily-kirichenko
    Contributor

    @saul where can Huge/Dense.sln be found? gen.fsx does not generate such folder:

    image

  19. saul commented on May 13, 2018

    @saul
    ContributorAuthor

    @vasily-kirichenko visualfsharp\tests\projects\stress\huge\dense\Dense.sln

  20. davkean commented on May 13, 2018

    @davkean
    Member

    @saul Let's open a new issue to track this so that we don't lose track of it.

  21. cartermp commented on May 13, 2018

    @cartermp
    Contributor

    @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.

  22. saul commented on May 13, 2018

    @saul
    ContributorAuthor

    @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').

  23. davkean commented on May 13, 2018

    @davkean
    Member

    K, that will be the following:

    1. Load projects (sync)
    2. Kick off design-time (async)
    3. When design-time build results arrive, process language-service data (sync on UI thread)

    Dependencies node issue is known and will because we can't catch the UI thread due to too much work done on it.

  24. dsyme commented on May 13, 2018

    @dsyme
    Contributor

    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 :)

  25. reopened this on May 13, 2018
  26. cartermp commented on May 14, 2018

    @cartermp
    Contributor

    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.

  27. modified the milestones: , 15.8 on Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-MediumRegression

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions