
ValheimBuildOptimization
A Valheim BepInEx optimization plugin for large builds, featuring spatial renderer batching, fire and light culling, optional wear-and-tear calculation bypasses, and built-in performance diagnostics.Valheim Build Optimization
Updated for Valheim 1.0: more FPS for your biggest builds.
Valheim Build Optimization is a BepInEx client-side performance mod for bases.
In one test on a base with 24,000 instances, average FPS rose from about 20 to 55. That's a gain of about 35 FPS, or 175% over the baseline. Results vary with hardware, base layout, active effects, settings, and other installed mods.
If you encounter any issues or have suggestions, please don’t hesitate to DM me on Discord: draco_alias
Its main job is to reduce the rendering, lighting, particle, structural, and optional diagnostic work caused by thousands of loaded build pieces. The mod is designed around targeted optimizations. Expensive systems are changed only when the mod can identify a reasonably safe case, and experimental systems have separate switches so they can remain completely dormant during normal play.
The project began as a build-piece profiler, so it also includes an optional in-game diagnostics window for measuring scene, rendering, physics, fire, batching, collider, script, and network activity.
Special thanks to u/keepoursxnity for providing detailed testing feedback and designing the mod icon! I also want to thank the Valheim community for the support, suggestions, and encouragement.
Requirements
- Valheim
- BepInEx 5
- A client running the mod
Install ValheimBuildOptimization.dll in:
Valheim/BepInEx/plugins/
Configuration is created in:
Valheim/BepInEx/config/valheim.buildpieceprofiler.cfg
The BepInEx Configuration Manager mod is recommended, but not required.
AI Assistance Disclaimer
This mod was developed with some AI assistance due to time constraints. All creative decisions, core functionality, fundamental code implementation, overall architecture, and design choices were made by me. AI was primarily used to help streamline development, assist with debugging, and handle repetitive tasks.
Thank you for your understanding and support!
Configuration Menu
Open Valheim Build Optimization in Configuration Manager. Essentials contains renderer batching, the full-detail batching option, fire optimization and its lighting mode, the support and weather-wear bypass, and the profiler and its shortcut.
Turn on Show developer settings, then close and reopen the menu to reveal tuning, diagnostics, and experimental features in Developer: sections. Turn it off and reopen the menu to hide them again. This switch only controls what is shown. Any features you enabled stay enabled.
The underlying config sections and keys are unchanged. All settings are still available in the BepInEx config file.
Existing configuration files keep their saved values after an update. Use Configuration Manager's Reset button for individual settings. See Configuration Defaults for every default and why it was chosen.
Fire Optimization
Fire optimization works on supported fireplaces, torches, sconces, braziers, hearths, bonfires, and similar fire pieces.
Banana Explanation
If monkey put fire sticks in banana house, banana house warm, banana house pretty, monkey happy.
But monkey put many fire sticks. Maybe too many fire sticks. Fire sticks not lazy. Fire sticks wiggle flame, throw sparkle, make light, think about shadow, do tiny fire dance. Fire sticks eat FPS banana.
If monkey looking at fire, okay. Fire doing fire job. Monkey see pretty fire.
But if monkey not looking at fire, fire still working. Monkey on other side of house staring at stone wall, but fire sticks still dance like monkey watching. Computer still work. FPS banana still disappear.
Mod says, "Why fire work? Monkey no see fire."
So hidden fire goes sleepy. Big expensive light takes nap. Tiny cheap banana glow stays awake so room still look warm and not dead.
When monkey look back, fire wakes up fast. Fire wiggle again. Fire sparkle again. Fire says, "I was working. Promise."
Same banana house. Same pretty fire when monkey see it. Less invisible fire work when monkey no see it. More FPS banana for monkey.
Technical Explanation
The fire system registers loaded Fireplace components in small batches. A fire needs a valid network record, a name matching the configurable allowlist, and both lights and particle systems. Newly loaded fireplaces are queued individually. The optimizer scans loaded fireplaces when it starts, when the allowlist changes, or when the optional fallback scan is enabled.
Each candidate is evaluated at a configurable interval using the main camera's field of view. Optional wall-blocking checks use a limited number of non-allocating raycasts or spherecasts per update. Fresh results are reused while the camera remains close to the point where they were taken. Visible candidates with expired results can use the cast budget, with priority given to already-culled fires that previously tested as blocked. A stale result no longer counts as blocked.
The optimizer uses grace periods in both directions:
- A fire must remain hidden before optimization starts.
- A fire must remain relevant before its original state is restored.
These delays reduce state cycling when the camera passes wall edges or the player turns rapidly.
When a fire enters an optimized state, the mod records:
- original light enabled states and culling masks;
- particle playback and emission states;
- renderer shadow-casting modes;
- enabled states of known light-flicker or light-LOD scripts.
The original fire lights are disabled and removed from rendering through their culling masks. Fire particle emission is disabled and existing particles are cleared. Known fire-light update scripts are paused so vanilla logic does not continually fight the optimized state.
When a fire becomes relevant again, the mod restores component settings and lets Valheim control which fire objects are active. It restarts particles individually on the currently active branch of a burning fireplace.
StaticLight Mode
Banana Explanation
Monkey cannot see ten fire sticks behind wall.
Monkey only sees warm glow through doorway.
Ten fancy lights still do ten jobs. Ten lights eat FPS banana for one glow.
Mod says, "Monkey need glow, not ten tiny suns."
Hidden lights go sleepy. One simple banana lamp covers the group.
Room still cozy. Computer less sad. More FPS banana.
Technical Explanation
StaticLight disables hidden original fire lights and effects but preserves approximate illumination using shadowless proxy lights.
Proxy lights are pooled. They are reused instead of repeatedly created and destroyed, reducing managed allocations and Unity object churn.
When clustered proxy lights are enabled, hidden fires inside the same world-space cell contribute to one representative light. The cluster averages source position and color, combines intensity conservatively, uses the largest source range, and disables real-time shadows. Each cluster light is updated once per optimizer cycle.
This mode is intended to preserve the visual impression of illuminated rooms while reducing the number of dynamic lights, shadow calculations, flicker scripts, and active particle systems.
FullCull Mode
Banana Explanation
Fire hidden behind three stone walls.
Monkey see no flame. Monkey see no glow. Monkey see only rock.
Mod says, "Why fire dance? Monkey see nothing."
Whole fire show goes sleepy until monkey can see it again.
No wasted fire dance. More FPS banana.
Technical Explanation
FullCull disables hidden original lights, particle emission, fire particles, light-update scripts, and fire mesh shadow casting without creating a replacement light.
It provides the most aggressive fire reduction, but hidden rooms may become visibly darker through openings. StaticLight is the recommended visual-quality mode.
Spatial Renderer Batching
Banana Explanation
Without batching, monkey gives painter many tiny jobs.
"Paint wall one. Paint wall two. Paint wall three. Paint wall four."
Painter hears many orders. Computer gets tired. FPS banana gets eaten.
With batching, mod says, "These walls live together. Make one big paint job."
Monkey points at whole wall section and says:
"Paint this big wall chunk."
Same stones. Same building. Less yelling at painter. More FPS banana.
Technical Explanation
Renderer batching divides the world into configurable spatial cells. Eligible opaque, static build-piece renderers inside each cell are grouped by compatible rendering state and combined into generated meshes.
The system keeps original colliders and gameplay components. It disables only source renderers represented by a successful combined mesh.
Pieces are excluded when they are likely to change or require independent rendering. Examples include:
- doors, portals, containers, crafting stations, and machines;
- fireplaces, lights, and particle effects;
- animated or skinned objects;
- non-kinematic rigidbodies;
- transparent or incompatible materials;
- unsupported mesh layouts;
- lightmapped renderers;
- snow overlays that Valheim shows and hides as snow builds up or melts;
- renderers managed by vanilla level-of-detail groups, by default;
- configured name-filter matches.
Compatible renderers are grouped by material, layer, shadow mode, probe settings, sorting state, and other rendering properties. Groups are split when they would exceed the configured vertex limit.
Piece discovery and cell rebuilding are budgeted across frames. Placement, destruction, damage, repair, and health changes mark only the affected spatial cell for delayed rebuilding. The delay coalesces rapid construction changes into fewer mesh rebuilds.
Highlighting a batched piece temporarily suspends the affected combined renderer and shows its original renderers. A shared shadow caster also pauses during that handoff, and the remaining batches in that shadow group cast their own shadows until the shared caster resumes.
The system caches stable eligibility, renderer arrays, and LOD classification to avoid repeatedly scanning the same component hierarchies.
Renderer Batching.ForceHighestLod opts into the previous behavior of batching eligible highest-detail meshes. This can improve batching coverage while increasing geometry at a distance. Its effect depends on the base and draw-distance settings.
Renderer Batching.EnableLodAwareBatching is an opt-in alternative. Keep EnableRendererBatching on and turn ForceHighestLod off. Compatible groups in each cell get one combined mesh per detail level, made from Valheim's original meshes. Unity selects the detail level, fade, and final cull using the source thresholds and a shared reference point for the batch. Nearby pieces in one batch can transition together, so timing can differ from individual vanilla pieces. This does not extend the game's world streaming range.
The experimental path requires one compatible non-snow renderer at each level. If any level is unsupported or the group is too small to merge, the originals stay in use. Snow stays under vanilla control, and LOD-aware batches cast their own shadows instead of using experimental shadow clusters. Storing multiple meshes can increase memory use and rebuild time, so the vertex budget applies to all variants in a batch together.
To compare modes, use the same camera position and settings and wait for Dirty cells and Discovery remaining to reach zero. LOD groups batched / compatible shows coverage, and Visible LOD variants: highest / lower shows whether Unity is using the lower-detail meshes. Check transitions while approaching a build, then highlight, repair, and remove a piece to verify the original visuals restore correctly.
Shadow Optimization
Banana Explanation
Monkey squishes many walls into one big painting.
Painter happy. Computer happy.
But sun still remembers old walls.
"Wall one, make shadow. Wall two, make shadow. Wall three, make shadow."
Too many shadow chores. FPS banana gets nibbled.
Shadow optimizer tries to give sun fewer, simpler shadow shapes.
Good idea, but sun is picky. Sometimes sun no like banana math.
Feature is experimental, so it sleeps behind master switch until monkey says yes.
Technical Explanation
The shadow system is an experimental extension of renderer batching. It considers compatible opaque combined batches that still cast real-time shadows and attempts to replace several shadow casters with one shadow-only mesh.
Clusters are accepted only when they meet configurable requirements for:
- minimum visible source batches;
- minimum estimated shadow draw calls saved;
- maximum total generated vertices;
- maximum vertices per draw call saved;
- maximum world-space bounds size.
Exact shadow meshes contain position and triangle data without unnecessary normals or visual-material data. Source mesh geometry may be cached while exact clusters are active.
An optional simplified structural mode represents configured walls and roofs with box-like shadow geometry. This can greatly reduce vertex cost, but may change shadow silhouettes.
Shadow optimization is disabled by default because exact shadow clusters can cost more geometry and culling precision than the draw calls they save. It should be tested separately from renderer batching.
Wear and Tear Optimization
Banana Explanation
Normally every building piece keeps asking:
"Am I supported? Is roof above me? Is rain touching me? Am I wet now? How about now?"
Many pieces ask many questions. Computer keeps answering. FPS banana gets chewed.
But monkey base has no collapse and no rain damage anyway.
Mod says, "Why ask about danger that no exist?"
Every piece gets permanent strong banana pillar and permanent invisible umbrella.
Piece feels safe. Piece stops asking. Computer gets quiet.
Same base. Less nervous wood. More FPS banana for monkey.
Technical Explanation
When enabled, the mod bypasses selected WearNTear methods:
- support updates are skipped;
- support queries return a configurable high value without storing it in the piece's vanilla support cache;
- support checks always succeed;
- cover updates are skipped;
- normal and ash roof checks succeed;
- wetness checks return false, including the underwater path of that check.
This is a gameplay option. The forced roof and support values can also affect snow accumulation and snow-load damage. Other damage paths, such as combat and lava, still run through Valheim. The game continues handling health, repairs, destruction, and persistence.
Turning the option off restores vanilla checks on subsequent game updates. In multiplayer, Valheim processes wear on the peer that owns each piece. A local setting does not enforce the same rules on other clients or the server.
Static Component Sleeping
Banana Explanation
Some decorations look still, but tiny monkey inside keeps turning wheel every frame.
Decoration no move. Decoration no change. Tiny monkey still work. FPS banana gets nibbled.
Sleeper wants to tell approved tiny monkey:
"Take nap. Wake up only when building changes."
Good for boring decorations.
But mod must be careful. Some tiny monkeys look decorative, but secretly run machine. Wrong monkey takes nap, machine breaks.
So feature is cautious and experimental. Only approved tiny monkeys may sleep.
Technical Explanation
This system profiles build-piece MonoBehaviour types that implement Update, LateUpdate, or FixedUpdate.
Sleeping is restricted by:
- an explicit exact-type whitelist;
- a gameplay-script denylist;
- structural-piece requirements;
- rigidbody and interaction safety checks.
Approved components may be disabled after a grace period. Placement, damage, repair, health changes, or highlighting restores them and schedules another sleep attempt.
The system currently has no broadly proven default target in vanilla Valheim, so its master switch, profiling, and sleeping are disabled by default. When the master switch is off, it performs no discovery or event work.
Compound Collider Clustering
Banana Explanation
Base floor has ten thousand tiny invisible boxes.
Boxes tell monkey where feet can stand. Boxes also tell hammer which floor piece monkey is pointing at.
Collider clustering says, "Why many tiny boxes in straight line? Make one long banana box."
Fewer boxes means less work. Computer happy.
But monkey hammer is picky. Monkey selection ray still needs to know exact floor piece that got hit.
If wrong box answers, monkey bonks wrong floor. Bad banana.
So feature is clever, risky, and currently experimental.
Technical Explanation
The collider system searches for enabled, non-trigger, static BoxCollider components on eligible structural pieces.
It excludes:
- colliders attached to moving rigidbodies;
- interactive and animated pieces;
- lights and effects;
- non-box collider types;
- configured name-filter matches.
Compatible boxes are grouped by layer and physics material. Only world-axis-aligned, collinear boxes with matching cross-sections may merge.
Original colliders remain active near the player. Beyond the configured activation distance, eligible cells may enable merged colliders and disable represented originals. A hysteresis gap separates activation and restoration distances.
Generated clusters include a damage proxy that maps a hit back to the nearest original source piece. This cannot perfectly preserve every possible collider lookup or mod interaction.
The system has measured as a performance loss in current large-base tests. It remains available for development but is disabled behind a master switch.
Network Activity Diagnostics
Banana Explanation
Monkey wants to know which machines keep sending banana paperwork.
Profiler watches paperwork. Profiler counts who writes most forms, who yells most, and who keeps bothering server.
Profiler does not stop paperwork. Profiler only spies and makes report.
Useful when monkey is testing. Not useful for normal banana life.
Leave spy monkey home unless monkey is hunting network problem.
Technical Explanation
The network diagnostics system maps build-piece ZNetView components to their ZDO records and can measure:
- attempted and changed ZDO writes;
- writes deduplicated by Valheim because the value was unchanged;
- data revision changes;
- ownership changes;
- build-piece RPC calls;
- active static and dynamic writers;
- global sent and received ZDO counters;
- the client change queue.
Global write and RPC hooks are installed dynamically only while both the network master switch and profiling option are enabled. They are removed when the system is disabled.
This system does not currently throttle networking. It is a diagnostic foundation for future work and is disabled by default.
Profiler
Banana Explanation
Monkey opens clipboard, counts everything, writes numbers, then closes clipboard.
Counting helps monkey see what is eating FPS banana.
But counting giant base also takes work. Clipboard monkey is not free.
Use when testing. Do not ask monkey to recount every second unless monkey actually needs numbers.
Technical Explanation
Press the configured profiler key, F7 by default, to open the in-game window when the profiler is enabled.
The window is organized into collapsed sections:
- global scene;
- global rendering;
- global physics;
- global effects;
- build-piece rendering;
- build-piece physics;
- build-piece effects;
- fire optimization;
- renderer batching;
- shadow optimization;
- static component sleeping;
- collider clustering;
- network activity;
- top light offenders.
Hover any section or statistic for a plain-language explanation.
Poll now collects a scene snapshot across several frames. The window shows when the snapshot is collecting and when the last one finished. Individual Unity scene searches still run on the game thread, and a snapshot can include changes that happened while it was collecting. The fire section uses live optimizer counts when fire optimization is active. Automatic polling is suppressed above 5,000 loaded pieces.
The profiler and automatic polling are both disabled by default for normal gameplay.
Future Work
- Investigate repeatable stutters at specific spots in large bases. They were reproduced with this mod absent, so start by capturing a fixed walking route in vanilla Valheim and measuring frame-time spikes before attributing them to any optimization.
Record a hitch
- Enable Show developer settings, reopen Configuration Manager, and turn on Developer: Hitch Detector > EnableHitchDetector. The regular profiler can stay off.
- Close the menu. Press F8 near the start of the route, wait one second, then walk through the hitch spots. Press F8 again to finish early, or let the 45-second capture finish.
- Look for
Hitch capture finishedinBepInEx/LogOutput.log. The report lists the worst events, their positions and zones, loaded instance counts, garbage collection counts, and timings for selected game methods. Streaming detail separates sector lookup, spawn work, and individual object creation. Location detail names the slowest world location and shows ground snapping, forced terrain generation, and dungeon generation times when those ran.
For the first capture, leave renderer batching, fire optimization, and experimental systems off. Use a copy of the world if changing support or weather-wear settings. The detector only times selected methods while recording; it changes no gameplay. The timings can overlap and do not account for all engine or GPU work.