Warning about server GC in F# project

Viewed 222

I am working on my very first F# project and I am experimenting with the Hopac library.

I am on dotnet version 3.1.300 on a Mac. I have initialized my project using the following:

dotnet new console --language F#
dotnet add package Hopac

And after writing using the Hopac library ran the program in the following way:

dotnet run

The runtime behaviour of the program works according to my expectations but I get the following warning:

WARNING: You are using single-threaded workstation garbage collection, which means that parallel programs cannot scale. Please configure your program to use server garbage collection.

As recommended in a few threads in SO to add the following clause:

<ServerGarbageCollection>true</ServerGarbageCollection>

I have tried the following in my fsproj configuration:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
  <ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>


 <PropertyGroup>
   <OutputType>Exe</OutputType>
   <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

 <ItemGroup>
    <Compile Include="Program.fs" />
 </ItemGroup>

 <ItemGroup>
  <PackageReference Include="Hopac" Version="0.4.1" />
 </ItemGroup>

</Project>

Additionally I have also tried:

<Project Sdk="Microsoft.NET.Sdk">

 <PropertyGroup>
   <ServerGarbageCollection>true</ServerGarbageCollection>
   <OutputType>Exe</OutputType>
   <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

 <ItemGroup>
    <Compile Include="Program.fs" />
 </ItemGroup>

 <ItemGroup>
  <PackageReference Include="Hopac" Version="0.4.1" />
 </ItemGroup>

</Project>

but the same warning persists. I am an absolute novice on .NET configuration files so am I making some obvious errors? Thanks

1 Answers

Create a runtimeconfig.template.json at the root of your project

{
      "configProperties": {
        "System.GC.Server": true
     }

}

To verify is working, inside your code print:

printfn "%A" System.Runtime.GCSettings.IsServerGC

It should be true.

For some reason the SDK version of the setting does not work.

Related