fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Transparent Compiler: High memory usage in FSAC

Open TheAngryByrd opened this issue 1 year ago • 0 comments

Please provide a succinct description of the issue.

Using the transparent compiler in FSAC, I've noticed large memory usage. After doing some investigation with dotnet-dump and dotmemory I've found two places that could be better:


The biggest issue stems from re-creating projects for each FSharpCheckFileResults.

https://github.com/dotnet/fsharp/blob/06c85f072f88009dafa8f478d59dac708cdc78ff/src/Compiler/Service/TransparentCompiler.fs#L1618

or FSharpCheckProjectResults.

https://github.com/dotnet/fsharp/blob/06c85f072f88009dafa8f478d59dac708cdc78ff/src/Compiler/Service/TransparentCompiler.fs#L1886

For a large project, this creates thousands of projects for every typecheck. I have a local fork that passes in None instead on the TC side while keeping the BC still passing in Some options. This has an the effect I was looking for but I doubt that's a desirable fix.


Secondly, the size factor in the CompilerCaches isn't publicly configurable. Meaning these checks can stay around in memory for quite a long time.

https://github.com/dotnet/fsharp/blob/06c85f072f88009dafa8f478d59dac708cdc78ff/src/Compiler/Service/TransparentCompiler.fs#L262 https://github.com/dotnet/fsharp/blob/06c85f072f88009dafa8f478d59dac708cdc78ff/src/Compiler/Service/TransparentCompiler.fs#L342

For larger projects, being able to change the weakly held and the strongly held references would be ideal.

Expected behavior

Memory usage is ok.

Actual behavior

Chrome isn't scared by much but it's definitely scared by this.

Known workarounds

Custom fork of FCS

Related information

Provide any related information (optional):

  • Operating system
  • .NET Runtime kind (.NET Core, .NET Framework, Mono)
  • Editing Tools (e.g. Visual Studio Version, Visual Studio)

TheAngryByrd avatar Apr 02 '24 20:04 TheAngryByrd