F# compiler is really slow when trying to compile .net8.0 project with SDK 8.0.303 · Issue #17501 · dotnet/fsharp · GitHub
Skip to content

F# compiler is really slow when trying to compile .net8.0 project with SDK 8.0.303 #17501

Closed

Description

@NogginBops

Repro steps

Provide the steps required to reproduce the problem:

  1. Clone this specific commit: https://github.com/BoyBaykiller/opentk/tree/5c9dc6e6f0ec4c911fe05357dbfccc7e81d1842f
  2. Try to compile this test project using dotnet build -v:n .\tests\OpenTK.Tests\OpenTK.Tests.fsproj

Expected behavior

The compiler should compile the project (this particular commit has a runtime error, but that shouldn't matter).

Actual behavior

The compiler never finishes compiling the project.

Known workarounds

Switching to .net6.0 fixes the issue.

Related information

I also tried targeting and compiling the project with SDK Version: 9.0.100-preview.6.24328.19 and I still get the hang.

Provide any related information (optional):

  • Operating system: Windows 10
  • .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET Core 8.0.303
  • Editing Tools (e.g. Visual Studio Version, Visual Studio): Visual Studio 2022 Version 17.10.5

Activity

  1. added this to the Backlog milestone on Aug 6, 2024
  2. added
    Impact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.
    on Aug 7, 2024
  3. vzarytovskii commented on Aug 7, 2024

    @vzarytovskii
    Member

    So, the bad news is that I can't reproduce it on my mac, on both net7.0 and net8.0 as targets, compilation takes about a minute (47-55 seconds) on my machine (M2 macbook). net6.0 in main with the same SDK (8.0.100) takes about 4 seconds, which leads me to believe that it is the same sort of issue as described in fsprojects/Fleece#146.

    TL;DR of the issue is: around .NET7 BCL rolled out "Static abstracts in interfaces" feature (which led to much bigger interfaces hirearchy), at the same time we rolled out support for static abstracts as well as some changes to SRTPs. And what I think is happening is that once you introduce new BCL, some of the functionality in your tests is making typechecking go brrr, and performance degrades significantly, see discussion in the issue above, as well as Don's comment in fsharp/fslang-design@71cd2e0.

    Conclusion: with all this in mind, the the best current course of action (for us or contributors) would be to:

    1. Take current compiler from main.
    2. Build it (Release).
    3. Create a global.json file pointing to latest .NET9 SDK (preview 6 at the moment of me commenting it).
    4. Include it in the project from OP (tests project, from master branch, point to custom compiler via UseLocalCompiler.Directory.Build.props importing).
    5. Profile it with net6.0 (default) target.
    6. Change target to net8.0 (or switch branch to otk5-add-matrx-simd-equal, bba4019df27b0a54ff48ca2205d681dbe990824b at the moment of me commenting it).
    7. Include custom compiler there again. Profile it again.
    8. See what's different/what's wrong.
    9. Try to make it better.

    As a temporary workaround(s), there were some comments from @gusty in the original issue in Fleece, which might help.

  4. vzarytovskii commented on Aug 7, 2024

    @vzarytovskii
    Member

    The worst part is that the more people will move to net8.0 as TFM, the more people might hit this issue. I will try to collect some profiles once I have some free time, unless someone will beat me to it.

  5. vzarytovskii commented on Aug 7, 2024

    @vzarytovskii
    Member

    Profiles for

    1. master branch with tests project upgraded to net6.0:
      net6.zip
    2. otk5-add-matrx-simd-equal branch built with no changes (net8.0):
      net8.zip

    Running via .NET9p6 runtime host, with net8 SDK assemblies, on latest main of compiler.

    In case if someone wants to look at it.

  6. vzarytovskii commented on Aug 7, 2024

    @vzarytovskii
    Member

    Compiler spent a minute (out of ~2 under profiling) in just getting interfaces for all types:
    image

    Additionally, some type directed conversions are involved:
    image

    (I presume, when we try to find conversions we need to traverse all interfaces)

  7. vzarytovskii commented on Aug 7, 2024

    @vzarytovskii
    Member

    I will experiment with caching stuff more once I'm off of work.

  8. changed the title [-]F# compiler hangs when trying to compile .net8.0 project with SDK 8.0.303[/-] [+]F# compiler is really slow when trying to compile .net8.0 project with SDK 8.0.303[/+] on Aug 8, 2024
  9. added
    Area-CompilerCompiler-related issues which don't belong to other categories
    on Aug 19, 2024
  10. 25 remaining items

  11. baronfel commented on Apr 7, 2025

    @baronfel
    Member

    @T-Gro you should talk to Jared about his complog tool. I think Roslyn uses it in part to make it easy to extract out these kind of calls into something that can be independently tested across versions.

  12. haraldsteinlechner commented on Apr 7, 2025

    @haraldsteinlechner

    @T-Gro thanks for clarification and the great work. Yes i will set something up!

  13. NogginBops commented on Jul 5, 2025

    @NogginBops
    Author

    Is this still not fixed for the .net8 or .net9 sdk?

    I still have multi-minute builds and it's very bad...

  14. majocha commented on Jul 6, 2025

    @majocha
    Contributor

    Hi @NogginBops, the fix is currently enabled only under language version preview.
    Please try setting

    <PropertyGroup>
        <LangVersion>preview</LangVersion>
    </PropertyGroup>
    

    in your projects.

  15. NogginBops commented on Jul 6, 2025

    @NogginBops
    Author

    Using <LangVersion>preview</LangVersion> does indeed help compile times, though it does still take around a minute to compile the project. That's down from a 17 minute build, so it definitely helps, thanks.

  16. charlesroddie commented on Jul 11, 2025

    @charlesroddie
    Contributor

    Given that the preview exists, I'll redo #18225 and get some timings of builds with netstandard2.0, dotnet9 without language preview, and dotnet9 with language preview.

    Hopefully it works and then we can push to get this out of LangPreview and also into IDEs!

  17. NogginBops commented on Aug 25, 2025

    @NogginBops
    Author

    I'm coming back to this issue again and again. IntelliSense is unusably slow, it takes multiple minutes to get error messages and even syntax highlighting is broken. I guess this is also possibly related to (or made worse by) #18807 as we are also using xUnit in this project.

    Compiling from command line does seem to alleviate the issue, but it doesn't help IDE performance...

  18. majocha commented on Aug 25, 2025

    @majocha
    Contributor

    @NogginBops I think the changes to caching to make this faster are already in. At least in VS preview.

    Edit: NOPE.

  19. NogginBops commented on Aug 26, 2025

    @NogginBops
    Author

    The issues I'm describing are experienced on the opentk5.0 branch.
    https://github.com/opentk/opentk/tree/opentk5.0
    The current master branch uses net6.0 and isn't affected by this problem.

    Here is a video showing what I'm experiencing:
    https://github.com/user-attachments/assets/10fa70e2-c7cc-4aed-8dd5-8e84d74a2624

  20. vzarytovskii commented on Aug 26, 2025

    @vzarytovskii
    Member

    The issues I'm describing are experienced on the opentk5.0 branch. https://github.com/opentk/opentk/tree/opentk5.0 The current master branch uses net6.0 and isn't affected by this problem.

    Here is a video showing what I'm experiencing: https://github.com/user-attachments/assets/10fa70e2-c7cc-4aed-8dd5-8e84d74a2624

    What's the VS version? The initial fix was only affecting compiler, not IDE. VS fix went in much later, May 1st (#18499), and was merged in VS even later, June 16th (#18691).

    I have suspicion this didn't end up in 17.14? @T-Gro

  21. majocha commented on Aug 26, 2025

    @majocha
    Contributor

    The issues I'm describing are experienced on the opentk5.0 branch.

    Right! I forgot.

    Unfortunately, I can confirm the fix is not in most recent 17.14.

  22. charlesroddie commented on Sep 15, 2025

    @charlesroddie
    Contributor

    How does the compilation fix get out of preview and can that be done asap? F# compiling slowly with modern dotnet is an urgent problem and I heard teams are rushing things in now for dotnet10. @vzarytovskii @T-Gro

  23. vzarytovskii commented on Sep 15, 2025

    @vzarytovskii
    Member

    How does the compilation fix get out of preview and can that be done asap? F# compiling slowly with modern dotnet is an urgent problem and I heard teams are rushing things in now for dotnet10. @vzarytovskii @T-Gro

    Usually it has to be bumped to specific language version (or removed from under the flag in general) once it's close to release, not sure if the window is closed already for NET10 or if it was moved from under the preview already. It's a question to @T-Gro

    Update:

    It already is 10

  24. T-Gro commented on Sep 15, 2025

    @T-Gro
    Member

    It is in for .NET 10.
    Specifically, if you use the preview VS2026 + .NET10rc1, you should see the improvement 👍

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

    Area-CompilerCompiler-related issues which don't belong to other categoriesBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.

    Type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions