如何通过 dotnet fsi 使用服务器垃圾回收?

How do I use server garbage collection with dotnet fsi?

我想通过 dotnet fsi 使用服务器垃圾回收。我该怎么做?

垃圾收集应该可以通过以下两个来源中引用的运行时设置进行配置:

  1. https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet
  2. https://docs.microsoft.com/en-us/dotnet/core/run-time-config/

我正在使用 windows 和 dotnet 5 预览版 SDK。 dotnet fsi 运行良好。

我制作了以下 fsi.runtimeconfig.json 文件并将其放置在 C:\Program Files\dotnet:

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

但是,当我调用 dotnet fsi --runtimeconfig fsi.runtimeconfig.json 时出现以下错误:

> dotnet fsi --runtimeconfig "fsi.runtimeconfig.json"


error FS0243: Unrecognized option: '--runtimeconfig'

Exception by fsi.exe:
System.Exception: Error creating evaluation session: StopProcessingExn None
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1639.Invoke(String message) in F:\workspace\_work\s\src\fsharp\FSharp.Core\printf.fs:line 1639
   at FSharp.Compiler.Interactive.Shell.FsiCommandLineOptions..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TcConfigBuilder tcConfigB, FsiConsoleOutput fsiConsoleOutput) in F:\workspace\_work\s\src\fsharp\fsi\fsi.fs:line 726
   at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, Boolean fsiCollectible, FSharpOption`1 legacyReferenceResolver) in F:\workspace\_work\s\src\fsharp\fsi\fsi.fs:line 2484
   at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.Create(FsiEvaluationSessionHostConfig fsiConfig, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, FSharpOption`1 collectible, FSharpOption`1 legacyReferenceResolver) in F:\workspace\_work\s\src\fsharp\fsi\fsi.fs:line 2825
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Sample.FSharp.Compiler.Interactive.Main.evaluateSession(String[] argv) in F:\workspace\_work\s\src\fsharp\fsi\fsimain.fs:line 269

如果我省略运行时配置选项,fsi 会启动,但 System.Runtime.GCSettings.IsServerGCfalse

对于MacOs/linux: 您需要更改 dotnet.runtimeconfig.json。位于最新的 dotnet SDK 版本中,例如/usr/local/share/dotnet/sdk/3.1.301.

对于Windows: 您需要更改位于 Fsharp 文件夹中的 fsi.runtimeconfig.json 以获得最新的 SDK 版本,例如C:\Program Files\dotnet\sdk.0.100-preview.4.20258.7\FSharp

{
  "runtimeOptions": {
    "tfm": "netcoreapp3.1",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "3.1.5"
    },
    "configProperties": {
      "System.GC.Server": true
   }
  }
}

dotnet fsi

> System.Runtime.GCSettings.IsServerGC;;
val it : bool = true