Skip to content

Commit

Permalink
Adds more garbage collection settings (#1896)
Browse files Browse the repository at this point in the history
* Adds more garbage collection settings

* Adds back use of deprecated conserveMemory setting
  • Loading branch information
TheAngryByrd authored Jul 23, 2023
1 parent 13038fd commit db2c0ea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
24 changes: 22 additions & 2 deletions release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@
"FSharp.fsac.conserveMemory": {
"default": false,
"description": "Configures FsAutoComplete with settings intended to reduce memory consumption. Requires restart.",
"type": "boolean"
"type": "boolean",
"deprecationMessage": "This setting is deprecated. Use FSharp.fsac.gc.conserveMemory instead."
},
"FSharp.fsac.dotnetArgs": {
"default": [],
Expand All @@ -542,6 +543,25 @@
},
"type": "array"
},
"FSharp.fsac.gc.conserveMemory" : {
"markdownDescription": "Configures the garbage collector to [conserve memory](https://learn.microsoft.com/en-us/dotnet/core/runtime-config/garbage-collector#conserve-memory) at the expense of more frequent garbage collections and possibly longer pause times. Acceptable values are 0-9. Any non-zero value will allow the [Large Object Heap](https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap) to be compacted automatically if it has too much fragmentation. Requires restart.",
"type": "integer",
"minimum": 0,
"maximum": 9
},
"FSharp.fsac.gc.heapCount" : {
"default": 2,
"markdownDescription": "Limits the number of [heaps](https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals#the-managed-heap) created by the garbage collector. Applies to server garbage collection only. See [Middle Ground between Server and Workstation GC](https://devblogs.microsoft.com/dotnet/middle-ground-between-server-and-workstation-gc/) for more details. This can allow FSAC to still benefit from Server garbage collection while still limiting the number of heaps. Requires restart.",
"type": "integer",
"required": [
"FSharp.fsac.gc.server"
]
},
"FSharp.fsac.gc.server": {
"default": true,
"markdownDescription": "Configures whether the application uses workstation garbage collection or server garbage collection. See [Workstation vs Server Garbage Collection](https://devblogs.microsoft.com/premier-developer/understanding-different-gc-modes-with-concurrency-visualizer/#workstation-gc-vs-server-gc) for more details. Workstation will use less memory but Server will have more throughput. Requires restart.",
"type": "boolean"
},
"FSharp.fsac.netCoreDllPath": {
"default": "",
"description": "The path to the \u0027fsautocomplete.dll\u0027, a directory containing TFM-specific versions of fsautocomplete.dll, or a directory containing fsautocomplete.dll. Useful for debugging a self-built FSAC. If a DLL is specified, uses it directly. If a directory is specified and it contains TFM-specific folders (net6.0, net7.0, etc) then that directory will be probed for the best TFM to use for the current runtime. This is useful when working with a local copy of FSAC, you can point directly to the bin/Debug or bin/Release folder and it\u0027ll Just Work. Finally, if a directory is specified and there are no TFM paths, then fsautocomplete.dll from that directory is used. Requires restart.",
Expand Down Expand Up @@ -1720,4 +1740,4 @@
"url": "https://github.com/ionide/ionide-vscode-fsharp.git"
},
"version": "7.8.2"
}
}
36 changes: 33 additions & 3 deletions src/Core/LanguageService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,36 @@ Consider:
let enableProjectGraph =
"FSharp.enableMSBuildProjectGraph" |> Configuration.get false

let conserveMemory = "FSharp.fsac.conserveMemory" |> Configuration.get false
let tryBool x =
// Boolean.TryParse generates: TypeError: e.match is not a function if we don't call toString first
match Boolean.TryParse(x.ToString()) with
| (true, v) -> Some v
| _ -> None

let tryInt x =
match Int32.TryParse(x.ToString()) with
| (true, v) -> Some v
| _ -> None

let oldgcConserveMemory =
"FSharp.fsac.conserveMemory"
|> Configuration.tryGet
|> Option.map string
|> Option.bind tryBool

let gcConserveMemory =
"FSharp.fsac.gc.conserveMemory" |> Configuration.tryGet |> Option.bind tryInt

let gcConserveMemory =
// prefer new setting, fallback to old, default is 0
match gcConserveMemory, oldgcConserveMemory with
| Some x, _ -> x
| None, Some true -> 9
| None, _ -> 0

let gcHeapCount = "FSharp.fsac.gc.heapCount" |> Configuration.get 2

let gcServer = "FSharp.fsac.gc.server" |> Configuration.get true

let parallelReferenceResolution =
"FSharp.fsac.parallelReferenceResolution" |> Configuration.get false
Expand Down Expand Up @@ -788,8 +817,9 @@ Consider:

let fsacEnvVars =
[ yield! fsacEnvVars
if conserveMemory then
yield "DOTNET_GCConserveMemory", box "9"
yield "DOTNET_GCHeapCount", box (gcHeapCount.ToString("X")) // Requires hexadecimal value
yield "DOTNET_GCConserveMemory", box gcConserveMemory
yield "DOTNET_GCServer", box gcServer
if parallelReferenceResolution then
yield "FCS_ParallelReferenceResolution", box "true" ]

Expand Down

0 comments on commit db2c0ea

Please sign in to comment.