Wildermine Performance Breakthrough: 248x Faster Paint Operations
We achieved a massive performance breakthrough in Wildermine, our upcoming procedural environment and trees puzzle game. By implementing a copy-on-write optimization for level editing, we’ve made paint operations 248x faster with 99.7% less memory usage. Creating levels feels incredibly responsive.
The Problem
Wildermine’s level editor allows players to paint terrain across a 60×60 grid with 6 different layers (Water, Rock, Grass, Trees, Features, Flowers). To support undo/redo functionality, we needed to clone the entire level state before each paint stroke.
The original approach was brutally expensive:
- 3,600 cells × 6 layers = 21,600 tile references copied on every mouse-down
- Each paint stroke took ~10ms just for cloning
- Memory usage: ~168.8 KB per stroke
For a smooth editing experience, this was way too slow.
The Solution: Copy-on-Write
We implemented a copy-on-write pattern that fundamentally changes how level cloning works:
shallowClone()
- Creates a new level that shares cell references with the originalcloneCell(x, y)
- Deep-clones only the specific cell being modified- Smart mutation -
setTileMut()
now clones cells on-demand before modification
Instead of cloning all 3,600 cells upfront, we only clone the cells that are actually painted—typically 10-100 per stroke.
The Results
We built a comprehensive test harness to measure objective improvements:
Paint Stroke Performance (10 cells)
Approach | Time | Improvement |
---|---|---|
OLD (full clone) | 3.296ms | — |
NEW (copy-on-write) | 0.013ms | 248.6x faster |
That’s 99.6% faster for typical paint operations!
Large Brush Performance (100 cells)
Approach | Time | Improvement |
---|---|---|
OLD (full clone) | 3.372ms | — |
NEW (copy-on-write) | 0.083ms | 40.8x faster |
Even with large brushes, we’re still 97.5% faster.
Memory Efficiency
Metric | OLD | NEW | Savings |
---|---|---|---|
Memory per stroke | ~168.8 KB | ~0.5 KB | 99.7% |
Cells cloned | 3,600 | 10-100 | ~97-99% |
Real-World Impact
What does this mean for players?
- Ultra-responsive painting - Paint strokes are now nearly instantaneous
- Faster undo/redo - No more waiting for the editor to catch up
- Smoother experience - Less memory churn means better overall performance
- Scales better - Works even faster with small brush strokes
Verification
All optimizations were verified with automated tests and manual confirmation:
✅ Unmodified cells are properly shared
✅ Modified cells are correctly cloned
✅ Copy-on-write produces identical results to full clone
✅ All 11 performance tests passing
Complete Test Results
Our comprehensive test harness validates every optimization with 11 automated tests covering cloning performance, paint stroke simulation, memory efficiency, and correctness verification—ensuring the 248.6x speedup and 99.7% memory reduction are real and reliable.
Technical Details
For developers interested in the implementation:
// Shallow clone: share cell references
shallowClone(): LevelV2 {
const shallowGrid = this.grid.map(row => [...row]);
// Return new level with shared cells
}
// Clone only the cell being modified
cloneCell(x, y): void {
const cell = this.grid[y][x];
this.grid[y][x] = {
[LayerIdV2.Water]: cell[LayerIdV2.Water],
[LayerIdV2.Rock]: cell[LayerIdV2.Rock],
// ... clone all layers
};
}
// Mutate safely with copy-on-write
setTileMut(x, y, layer, tileId) {
this.cloneCell(x, y); // Clone before write
this.grid[y][x][layer] = tileId;
}
What’s Next
This optimization unlocks new possibilities for Wildermine:
- Larger levels - We can now support bigger grids without performance hits
- More complex tools - Flood fill, selection tools, and advanced brushes become viable
- Better undo history - We can afford to keep more undo states in memory
Performance optimization isn’t just about speed—it’s about creating a better player experience. This breakthrough means Wildermine’s level editor will feel as smooth and responsive as players expect from a modern tool.
Want to learn more about Wildermine’s development? Follow our devlog for more technical deep-dives and progress updates!
Performance stats at a glance:
- 🚀 248.6x faster typical paint operations
- 💾 99.7% less memory per stroke
- ✅ 100% correctness verified by automated tests
- 🎮 Smoother experience for level creators