Fast NBT

Quick rating

Community listing page, reviews here may not be monitored by the author.

Fast NBT

No reviews yet

Speed up all kinds of NBT operations and improve game performance

Mod Loaders
Minecraft

About

Description

Fast NBT makes the NBT work Minecraft does constantly cheaper: reading tags, turning them into game objects, and loading them from chunks, packets, block states and ItemStacks.

CompoundTag

  • All kinds of get methods. In the vanilla game it first calls contains to check whether the key exists, then invokes get — two map lookups. Fast NBT merges those two operations into one and applies inlining, which greatly improves the lookup speed.
  • Iteration. Iterating with keySet paired with get is replaced by an approach that walks keys and values simultaneously, so writing and merging a compound no longer does a lookup for every entry.
  • Related classes. Operations that use those get methods in other related classes are optimized too.

ItemStack, block states and NBT I/O

  • ItemStack loading. Reading an ItemStack from NBT takes tag and ForgeCaps straight from the backing map instead of probing with two contains calls, and getOrCreateTagElement, getTagElement and removeTagKey resolve in a single lookup.
  • Block states. NbtUtils.readBlockState and getDataVersion read Name and Properties directly, instead of going through the vanilla contains / getString chain.
  • Chunk section palettes. Each palette entry normally goes through the full DFU codec chain — dispatch codec, registry lookup, one MapCodec per property, plus DataResult / Either / Pair / Optional allocations — on every chunk load and every save. Fast NBT resolves the canonical {Name, Properties} tag straight from the map. This is the largest win in the mod.
  • NBT I/O. Unlimited readers — every chunk load, plus level.dat and playerdata — skip a byte-accounting pass whose result is thrown away.

So the gains land where NBT is decoded in bulk: world and chunk loading, server autosaves (which re-encode every chunk), and the inventory, block entity and entity payloads that carry tagged ItemStacks. Fewer temporary objects on the palette path also means less GC pressure.

This is not a general performance mod: it touches nothing outside NBT, and it cannot help a workload that is bounded by disk or network. The savings scale with how much NBT a pack decodes, and are smallest in a plain vanilla world.

Configuration

config/fastnbt.toml is generated on first launch and gives each optimization its own switch:

enabled = true              # master switch for everything below

[features.itemStack]
    enabled = true

[features.blockState]
    enabled = true

[features.blockStateCodec]
    enabled = true

[features.nbtIo]
    enabled = true

The CompoundTag rewrites have no separate switch; the global enabled flag controls them.

How it stays safe

  • Only canonical data takes a fast path. Anything that is not canonical is reported as a decode error instead of being guessed at, and a key in Properties that the block does not have is ignored, exactly as in vanilla. For chunk palettes the caller turns a failed entry into air, so a world referencing blocks from an uninstalled mod still loads — with one log line per entry.
  • Encoding is never replaced. The palette optimization only speeds up decoding, so saved chunks and network packets stay byte-identical.
  • Injection conflicts. The optimizations replace or redirect vanilla methods and ship no non-destructive variant, so if another mod targets the same method, the last one applied wins. Test large packs before shipping them.

Licensed under the GNU LGPL v3.0 or later.