ItemOptimizer
A performance optimization mod for Barotrauma. Cuts unnecessary per-frame computation in large submarines under heavy mod loads.
Optimization only — no gameplay mechanics are changed. Every feature can be toggled individually in the in-game settings panel (ESC → ItemOptimizer).
Benchmark
Same save, ~17 content mods loaded (Deep Diving Armory, Barotraumatic, T.S.M MISSIONS, 九州武库 Rebalance, Enhanced EuropaWar, etc.). showperf fluctuation comparison:
- FPS: 76 → 146
- Update total: 13.16 ms → 8.02 ms (~5 ms/frame saved)
- MapEntity: 8.08 ms → 4.11 ms (~49% reduction)
- Update peak: 33.45 ms → 20.04 ms (spike flattened)
Results vary across submarines, mod combinations, and map stage. Light-mod or vanilla setups typically save 1–2 ms/frame.
Works on both client and server. LuaCs-enabled servers also benefit. Systematic server-side benchmarking is still pending — test data is welcome.
Requirements
Features
Zone Scheduling
- Submarines, wrecks, ruins, and outposts on the map are partitioned into independent zones, graded into 5 tiers by distance from the player: Full → Near → Throttled → Dormant → Unloaded
- Nearby zones run at vanilla update rate; distant ones step down progressively until fully frozen, then reactivate as the player approaches
- Most noticeable in long-running campaigns with many discovered locations
Smart Item Throttling
- Takes over the vanilla item update loop, classifies each item once per tick, and skips items that don't need a full update
- Items inside unopened containers are frozen until the container is opened
- Items lying on the ground update less frequently (wired items and items with critical components are excluded)
- Skipped items still receive minimum physics updates (position, buoyancy, network sync) — they don't vanish from the world
Component Rewrites
- Motion Sensor — replaced with hull-based spatial queries, skipping vanilla's per-entity collision checks
- Water Detector — reads hull water level directly, skipping vanilla's multi-step detection flow
- Relay — reduced to pure signal passthrough, redundant state checks removed
- Power Transfer (junction boxes, etc.) and Power Container (batteries/supercapacitors) — grid topology is cached, cutting repeated per-frame recomputation
- All rewrites preserve vanilla behavior, can be toggled individually, and have configurable update intervals
Signal Graph Accelerator
- Compiles circuit components (logic gates, sensors, etc.) into a topologically-sorted evaluation graph using register arrays, in place of vanilla's per-wire SendSignal calls
- Compiled circuits are evaluated in a single ordered pass, skipping intermediate signal dispatch overhead
- Accelerate mode: compiles 12 basic logic components (AND/OR/NOT gates, comparators, arithmetic, memory, etc.)
- Aggressive mode: additionally compiles Relay passthrough and Delay components; components with connection-bound StatusEffects are excluded for safety
- Cycles are auto-detected and converted to single-frame delays, preserving normal circuit behavior
Mod Item Management
- Auto-detects installed mods and classifies their items by activity level (High / Active / Normal / Static)
- Per-mod intensity slider — control how aggressively each mod's items are throttled
- Global intensity slider — adjust all mods at once
- Whitelist — mark items that should never be throttled. Add them via the settings panel, or hold the item and press the whitelist button on the HUD
- Per-item rules — fine-grained control for specific item types
Languages
12 languages built in: English, 简体中文, 繁體中文, Deutsch, Español, Français, 日本語, 한국어, Polski, Português (Brasil), Русский, Türkçe.
Translation contributions and corrections are welcome on GitHub.
Settings
In-game: press ESC → click "ItemOptimizer". Everything is grouped into collapsible sections. Config saves automatically.
Compatibility
This mod uses Harmony to patch vanilla methods. Most mods coexist without issue. The most likely conflict point is other mods that also modify MapEntity.UpdateAll. If you run into a compatibility issue, report it — I'll look into adding support.
FAQ
Q: Why are some systems on my submarine acting up?
To cut vanilla per-frame overhead, this mod replaces or throttles a few systems:
- Signal circuits are compiled into a batch-evaluated graph. Aggressive mode also takes over Relay passthrough and Delay components — a small number of circuits with connection-bound StatusEffects may behave differently.
- Motion/Water sensors, Relay, Power Transfer, and Power Container are swapped for slimmer implementations; edge cases may differ slightly from vanilla.
- Idle items and zones far from the player are frozen or throttled, reactivating when you approach.
Q: How do I revert it if something breaks?
Every optimization can be toggled individually. In-game: press ESC → click "ItemOptimizer":
- Circuit issues: switch "Signal Graph Accel" to Off, or step down from Aggressive to Accelerate
- Component issues: disable the specific rewrite (e.g. turn off the Relay rewrite to return to vanilla behavior)
- Items or zones frozen too aggressively: disable Zone Scheduling or lower the intensity slider
Changes take effect without restarting — config saves automatically.
Links
Source Code (GitHub)[github.com]
Discord[discord.gg]