Server-side performance optimization mod for Vintage Story.
- Side: server only (
requiredOnClient: false) - Dependency declared in
modinfo.json:game: 1.22.0(minimum-version semantics) - Target framework:
net10.0(Vintage Story 1.22 ships with .NET 10) - Validated operational window:
1.22.0+
- Reduce allocation pressure and GC churn in hot paths.
- Keep black-box behavior equivalent to vanilla gameplay logic.
- Fail safe: if optimization safety checks fail, fallback to vanilla-like paths.
EnableEntityListReuseEnableBlockListReuseEnableGetDropsListReuseEnableEventManagerListReuse
EnableChunkLoadingOptimizationEnableChunkUnloadingOptimization
EnableEntitySimulationOptimizationEnableCookingContainerOptimizationEnableContainerOptimizationEnableGridRecipeOptimizationEnablePropickReadingOptimization
EnableSendPlayerEntityDeathsOptimizationEnablePhysicsManagerListOptimizationEnablePhysicsManagerMethodListOptimizationEnableServerMainLinqOptimization
EnablePlaceholderOptimizationEnableWildcardFastMatchOptimization
EnableGetEntitiesAroundOptimizationEnableEntityDespawnPacketOptimizationEnableRecipeBaseLinqOptimization
EnableBroadcastLinqOptimizationEnableBulkEntityAttributesPacketOptimizationEnableClassRegistryFrozenOptimizationEnableGetPlayersAroundOptimization
PlaceholderOptimization:- patches
RegistryObject.FillPlaceHolder(string, OrderedDictionary<string,string>) - single-pass placeholder parsing with startup equivalence self-check
- patches
WildcardFastMatchOptimization:- patches
WildcardUtil.fastMatch(string,string) - compiled regex cache with LRU eviction for
@patterns only - vanilla 1.22 handles
*patterns optimally; Tungsten only adds compiled regex for@
- patches
GridRecipeOptimization:- patches
RecipeBase.MatchesShapeLess(moved from GridRecipe in 1.22) - eliminates 2 list allocations per shapeless recipe match
- patches
GetEntitiesAroundOptimization(v1.3.0):- patches
GameMain.GetEntitiesAround - reuses intermediate
List<Entity>via ThreadLocal with recursion guard - ~300-450 calls/sec continuous on active servers
- patches
EntityDespawnPacketOptimization(v1.3.0):- patches
ServerPackets.GetEntityDespawnPacket - single-pass loop replacing 3x LINQ Select().ToArray() chains
- patches
RecipeBaseLinqOptimization(v1.3.0):- patches
RecipeBase.MergeStacksandRecipeBase.MatchWildcardIngredients - eliminates LINQ iterator allocations in crafting recipe matching
- patches
BroadcastLinqOptimization(v1.3.1):- patches 3
ServerMainbroadcast overloads - eliminates LINQ
Any()/All()closure allocations in player filtering
- patches 3
BulkEntityAttributesPacketOptimization(v1.3.1):- patches
ServerPackets.GetBulkEntityAttributesPacket - reuses packet wrapper objects via ThreadStatic, eliminates 2 allocs/client/tick
- patches
ClassRegistryFrozenOptimization(v1.3.1):- compacts 19 ClassRegistry dictionaries via
TrimExcess()after mod loading - reduces memory waste and improves cache locality for registry lookups
- compacts 19 ClassRegistry dictionaries via
GetPlayersAroundOptimization(v1.3.1):- patches
ServerMain.GetPlayersAround - ThreadLocal list reuse with recursion guard (same pattern as GetEntitiesAround)
- patches
- Removed
EnableSendChunksListReuse- vanilla 1.22 usesFastList<T>which already implements zero-allocation clear - Removed
EnableRegistryResolveExperimentalOptimization- was 1.21.6-only experimental - Rewritten
GridRecipeOptimizer- target moved fromGridRecipetoRecipeBase, list types updated for 1.22 API - Refactored
WildcardFastMatchOptimization- vanilla 1.22 has same iterative matcher; now only intercepts@regex patterns - Target framework changed from
net8.0tonet10.0 - Minimum game version changed from
1.21.5to1.22.0 - IL signature manifest must be regenerated (all hashes changed due to .NET 10 recompilation)
- Patch failure: optimization remains disabled, vanilla path is preserved.
- Lifecycle safety:
- P1
EnableThreadLocalLifecycleReset: startup reset; fallback to vanilla allocations if reset fails. - P2
EnableReusableCollectionPoolConcurrentOptimization: concurrent pool path reset; fallback if reset fails. - P3
EnableReusableCollectionPoolConstructorCacheOptimization: constructor-cache reset; fallback toActivatorpath if reset fails. - P4
EnableUnifiedRuntimeCircuitBreaker: global runtime breaker reset; auto-disabled if reset fails. - P9
EnableIlSignatureManifestValidation: validates IL hashes before patching; auto-disables affected optimizations on mismatch. - P10
EnableBenchmarkHarness: starts benchmark session only when healthy.
- P1
- Runtime exceptions in integrated optimization keys degrade to vanilla-safe paths.
- Circuit-breaker status is visible in
/tungsten. - Benchmark harness failure auto-disables harness and preserves gameplay behavior.
- Build/package or obtain
Tungsten.zip. - Place it in
VintagestoryData/Mods/. - Start or restart the server.
- File:
VintagestoryData/ModConfig/tungsten.json - Most optimization toggles require server restart.
- Runtime/process toggles that apply immediately:
EnableAdvancedMonitoringEnableUnifiedRuntimeCircuitBreakerEnableBenchmarkHarnessEnableFrameProfiler
EnableAdvancedMonitoring: falseEnableCapacityTrimming: trueEnableThreadLocalLifecycleReset: trueEnableReusableCollectionPoolConcurrentOptimization: trueEnableReusableCollectionPoolConstructorCacheOptimization: trueEnableUnifiedRuntimeCircuitBreaker: trueEnableIlSignatureManifestValidation: trueEnableBenchmarkHarness: falseEnableFrameProfiler: false
BenchmarkProfile: "default"BenchmarkVariant: "A"BenchmarkSessionDurationSeconds: 600BenchmarkSampleIntervalMs: 5000
ObjectPoolMaxSize: 32ObjectPoolShrinkIntervalSeconds: 60TargetCollectionCapacity: 200TrimCheckInterval: 5000FrameProfilerSlowTickThreshold: 40
/tungstenshows optimization status + runtime health./tungsten all on|offtoggles all optimization flags (restart required)./tungsten <optimization> on|offtoggles one optimization flag./tungsten reloadreloads config and applies runtime-safe settings./tungsten stats [on|off]shows/toggles advanced monitoring./tungsten healthshows multi-mod patch conflicts and event handler counts./tungsten manifestdumps current IL signature hashes to server log./tungsten benchmarkharness [on|off]controls benchmark harness./tungsten frameprofiler on|off [thresholdMs]controls vanilla frame profiler integration.
- Prefix:
[Tungsten] - Optimization-specific tags, for example:
[PlaceholderOptimization][WildcardFastMatchOptimization][RuntimeCircuitBreaker][ILSignatureManifest][BenchmarkHarness]
- Automatic disable/fallback events are explicitly logged.
- Keep defaults and start server.
- Verify startup logs for disabled optimizations and safety warnings.
- Run representative workload.
- Use
/tungstenand/tungsten statsto inspect health. - If needed, run
/tungsten benchmarkharness onfor A/B sessions.
- Identify degraded key in runtime circuit-breaker status.
- Disable the specific optimization via command/config.
- Restart if toggle requires restart.
- Keep other optimizations enabled.
- Upgrade server.
- Review startup IL manifest validation logs.
- Confirm that critical keys are not auto-disabled due to signature drift.
- Re-run benchmark profile.
- Compatible with most content/gameplay mods.
- Harmony conflicts are possible when another mod patches identical methods.
- Main docs index:
Documentation/README.md - Detailed optimization summaries:
Documentation/Description/ - PR analysis and implementation docs:
Documentation/ImplementationInTungsten/ - Vanilla reference notes:
Documentation/ImplementationInVS/
Copyright (c) 2025 Zaldaryon - All Rights Reserved