ValheimCommunityPatchGC

v1.0.0·Updated 2026-09-30

Garbage collector tuning for Valheim dedicated servers: a pre-grown mark stack against 'Unexpected mark stack overflow' crashes, plus optional collector settings. Companion to Valheim Community Patch.

About this mod Author’s original text

Valheim Community Patch GC

Garbage collector tuning for Valheim dedicated servers, a companion to

Valheim Community Patch.

It shipped inside the Community Patch in 0.31.0 and moved out in 0.32.0. Reaching the collector's

settings means reading and writing the Mono runtime's own memory, which malware scanners flag, and

that should not weigh on a mod every player installs. This plugin needs only BepInEx.

What it does

Dedicated servers only; clients and listen hosts ignore it. Valheim runs Unity's incremental

garbage collector, and on a busy server each collection ends in one stop-the-world pass with no

time limit. On a large world that pass measured about 55 ms per GB of heap: 330 ms at 6 GB, 460 ms

at 8.4 GB. A bigger heap also means fewer collections, so the total time paused stays about the same

whatever the heap size. The same collection pass is where a large server can abort with

Unexpected mark stack overflow.

The settings live in the Server - Garbage Collector section of

BepInEx/config/MidnightsFX.ValheimCommunityPatchGC.cfg. Only the mark stack setting is on by

default; setting any of them to 0 gives back the game's own value.

  • GC Mark Stack Target Entries (Linux), default 4194304 (64 MiB) — grows the collector's mark

stack ahead of need. The collector normally grows it only after a pass that nearly overflowed it,

and a pass that does overflow it aborts the server.

  • GC Free Space Divisor (Linux), default 0 (the collector's own 3) — how far the heap grows

between collections. It trades pause length against frequency: lower gives fewer, longer pauses

and uses more memory; higher gives shorter, more frequent ones.

  • GC Time Slice Milliseconds, default 0 (the game's 3 ms) — the incremental collector's

per-frame budget. On a busy server it did not change the pauses; a longer slice only lengthens

the short pause that opens each collection.

The divisor and the mark stack reach the collector through symbols only the Linux server runtime

exports; on a Windows server they do nothing.

Console command

vcp_gc prints the collector's current state: whether it is incremental, the time slice as Unity,

Mono and the collector each see it, the divisor, the heap, the last rescan's dirty pages and the

mark stack. It also changes each setting live, so the effect can be watched on a profiler:

  • vcp_gc slice, vcp_gc divisor, vcp_gc markstack — set and save a value;

0 restores the game's own.

  • vcp_gc stats on|off (Linux) — the collector's own log: a few lines per collection with its

stop-the-world times and how much it rescanned. It goes to the server's standard error (or

GC_LOG_FILE, if that was set when the server started), not to the BepInEx log. Not saved.

An admin can run it remotely from their own console; that needs this plugin installed on their

client too, where it does nothing else. The replies are written to the server log.

Installation

Install it on the dedicated server with a mod manager, or drop ValheimCommunityPatchGC.dll into

BepInEx/plugins. It requires BepInEx

and is packaged with Valheim Community Patch 0.32.0 or later as a dependency. With Community Patch

0.31.x, which has its own copy of these settings, it logs a warning and does nothing.

Settings changed in the Community Patch 0.31.0 config are not carried over; set them again in this

plugin's config. The Community Patch's old Server - Garbage Collector section can be deleted.

Credit and sources

  • bdwgc and Unity's fork of it and of Mono — the collector's

source is the reference for these settings; no code was used.

  • Iron Gate Studio — Valheim itself; no game code is redistributed.

Install & use Install: BepInEx plugin

  1. The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
  2. Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
  3. Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
  4. Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.

Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file. In multiplayer, the host and every client need the same mods installed.

Dependencies

Install these first, or the mod will not work:

denikson-BepInExPack_ValheimMidnightMods-ValheimCommunityPatch

File & checksum

Filename
ValheimCommunityPatchGC-1.0.0.zip
File size
28.4 KiB