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

O(1) crafting-grid recipe matching for Vintage Story. Pure performance — no gameplay change.

The problem

Every time an item enters or leaves the crafting grid, Vintage Story scans every distinct recipe ingredient in the game to figure out what you might be making — on both the client and the server, on every single change.

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 per keystroke, and dragging items around the grid starts to feel sticky.

What it does

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.

  • O(1) per-slot match, regardless of recipe count
  • 35–70× faster than the vanilla scan at base-game scale
  • ~1 µs to match a grid once the index is warm
  • 0 changes to recipes, items, or world data

The numbers

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.

<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>

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.

Costs are modest and one-time. The index build runs in the background at world load — about 0.2 s on the base game, up to ~4.5 s on a 120k-item modpack — and the index itself takes roughly 1 MB in vanilla, up to ~15 MB on a very large pack.

How it works

  • Pre-expanded index.&nbsp;Wildcard and tag ingredients are resolved against the item registry once, so even they become direct code → recipe lookups instead of pattern scans.
  • Built off the main thread.&nbsp;The one-time build runs on a background thread, prewarmed as your world loads — crafting never freezes waiting on it.
  • Vanilla until ready.&nbsp;If you somehow craft before the index finishes, the game's own matcher handles it. There's never a wrong or missing result.
  • Engine stays the authority.&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.
  • Per-world, client and server.&nbsp;Each world builds its own index exactly once. Both sides benefit.

⚠️ This is a deep-engine Harmony patch

This mod doesn't add content — it replaces a core engine method (InventoryCraftingGrid.FindMatchingRecipe) at runtime using Harmony. It's built to be a transparent drop-in, but because it reaches into engine internals you should know:

  • It targets a specific Vintage Story version's internals, and&nbsp;may break between VS patches.
  • It can&nbsp;conflict with other mods that patch the same crafting-matching code&nbsp;(uncommon, but possible).
  • It changes&nbsp;no&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.
  • It falls back to the unmodified engine matcher whenever its index isn't ready, so it&nbsp;never produces a wrong craft.

Download

No download link is available for this entry right now.

Ratings & reviews

No ratings yet

Sign in to leave a rating or comment.