SANDBOX — this is a test environment. No servers are actually deployed and no real payments are charged.
Back to NxLabs

NxLabs / Vintage Story

Performant Crafting Grid

EBy Emmett_chef

Eliminates crafting-grid recipe-matching lag via a pre-indexed O(1) lookup.

Description

<p><strong>O(1) crafting-grid recipe matching for Vintage Story.</strong> <em>Pure performance — no gameplay change.</em></p> <h2>The problem</h2> <p>Every time an item enters or leaves the crafting grid, Vintage Story scans <strong>every distinct recipe ingredient in the game</strong> to figure out what you might be making — on both the client and the server, on every single change.</p> <p>On the base game that's quick enough. On a heavy modpack with tens of thousands of recipes and a six-figure item registry, that linear scan balloons to milliseconds <em>per keystroke</em>, and dragging items around the grid starts to feel sticky.</p> <h2>What it does</h2> <p>It builds a recipe index once, when your world loads, that maps each item code straight to the recipes it can contribute to — wildcards and tags included. After that, matching the grid is a constant-time hash lookup per slot.</p> <ul> <li><strong>O(1)</strong>&nbsp;per-slot match, regardless of recipe count</li> <li><strong>35–70×</strong>&nbsp;faster than the vanilla scan at base-game scale</li> <li><strong>~1 µs</strong>&nbsp;to match a grid once the index is warm</li> <li><strong>0</strong>&nbsp;changes to recipes, items, or world data</li> </ul> <h2>The numbers</h2> <p>The win scales with your recipe count: the engine's cost grows with the number of recipes, while this stays flat. Measured in an isolated benchmark against the real engine matching logic.</p> <table> <thead> <tr> <th>Scenario</th> <th>Vanilla-style scan</th> <th>This mod</th> <th>Speedup</th> </tr> </thead> <tbody> <tr> <td>~2,500 recipes</td> <td>~57 µs</td> <td>~1 µs</td> <td>~57×</td> </tr> <tr> <td>~2,650 recipes</td> <td>~73 µs</td> <td>~1 µs</td> <td>~72×</td> </tr> <tr> <td>100,000 recipes</td> <td>~22 ms</td> <td>~4 µs</td> <td>~5,800×</td> </tr> </tbody> </table> <p><em>Per single grid-match check. The "vanilla" column is a faithful transcription of the engine's own gather; both use the real recipe-matching predicate. In-game on a ~120k-item modpack, crafting goes from noticeably sticky to instant.</em></p> <p>Costs are modest and one-time. The index build runs in the background at world load — about <strong>0.2 s</strong> on the base game, up to <strong>~4.5 s</strong> on a 120k-item modpack — and the index itself takes roughly <strong>1 MB</strong> in vanilla, up to <strong>~15 MB</strong> on a very large pack.</p> <h2>How it works</h2> <ul> <li><strong>Pre-expanded index.</strong>&nbsp;Wildcard and tag ingredients are resolved against the item registry once, so even they become direct code → recipe lookups instead of pattern scans.</li> <li><strong>Built off the main thread.</strong>&nbsp;The one-time build runs on a background thread, prewarmed as your world loads — crafting never freezes waiting on it.</li> <li><strong>Vanilla until ready.</strong>&nbsp;If you somehow craft before the index finishes, the game's own matcher handles it. There's never a wrong or missing result.</li> <li><strong>Engine stays the authority.</strong>&nbsp;The mod only narrows down the candidate recipes faster; the engine's own recipe-match check still makes the final call, so outputs are identical to vanilla — bit for bit.</li> <li><strong>Per-world, client and server.</strong>&nbsp;Each world builds its own index exactly once. Both sides benefit.</li> </ul> <h2>⚠️ This is a deep-engine Harmony patch</h2> <p>This mod doesn't add content — it <strong>replaces a core engine method</strong> (<code>InventoryCraftingGrid.FindMatchingRecipe</code>) at runtime using Harmony. It's built to be a transparent drop-in, but because it reaches into engine internals you should know:</p> <ul> <li>It targets a specific Vintage Story version's internals, and&nbsp;<strong>may break between VS patches</strong>.</li> <li>It can&nbsp;<strong>conflict with other mods that patch the same crafting-matching code</strong>&nbsp;(uncommon, but possible).</li> <li>It changes&nbsp;<strong>no</strong>&nbsp;world data, recipes, or items — it's safe to add or remove from an existing save at any time. If it ever misbehaves, removing it returns you to exactly stock behavior.</li> <li>It falls back to the unmodified engine matcher whenever its index isn't ready, so it&nbsp;<strong>never produces a wrong craft</strong>.</li></ul>

Download

No download link is available for this entry right now.

Ratings & reviews

No ratings yet

Sign in to leave a rating or comment.