Skip to content

[26.3 client] Block info (path node cache + block state flags) is reset on every tag reload (every server join) and rebuilt lazily on the first block update: 170-290 ms render-thread freeze in-world shortly after joining #810

Open

Description

@D3M0NQTR

Lithium 0.26.3 is still the newest 26.3 release (re-checked 19 Nov 2026 against the newest 26.3 release on Modrinth).

Version Information

lithium-fabric-mc26.3-0.26.3 (client side; Fabric Loader 0.20.1, Fabric API 0.165.2+26.3). The code involved is unchanged at the current develop head.

Expected Behavior

Joining a multiplayer server does not stall the render thread once the world is already visible.

Actual Behavior

A few seconds after a (re)join, when the world is already shown and the player can move, one frame takes 170-290 ms. JFR puts 22 of 24 render-thread samples in that frame inside BlockInfoInitializer.initializeBlockInfo, entered from a block-update packet (ClientPacketListener.handleBlockUpdate -> LevelChunkSection.setBlockState -> lithium$trackBlockStateChange -> lithium$getAllFlags -> handleUninitializedBlockStateFlags -> initializeBlockInfoAndGetFlags).

Cause, from the sources:

  • mixin.util.initialization.MappedRegistryMixin injects at the return of MappedRegistry.prepareTagReload and calls BlockInfoInitializer.resetBlockInfo() for the block registry. On the client every server join applies tags, so every join wipes the per-blockstate path-node cache and block-state flags.
  • Nothing rebuilds them until the first lithium$getAllFlags() on a state whose flags are -1; initializeBlockInfoAndGetFlags then runs initializeBlockInfo(), which recomputes the path node types and all BlockStateFlags for every entry of Block.BLOCK_STATE_REGISTRY under BLOCK_INFO_INITIALIZATION_LOCK, on whatever thread asked. With a large pack (about 430 mods, so a large block-state registry) that is 170-290 ms, and the first caller is normally the first block update after the chunks arrive, i.e. a visible in-world freeze. Faster joins make the in-world hit more likely, because the first block update arrives sooner after the world appears.

Reproduction Steps

  1. Client with Lithium and a large mod set (the cost scales with the number of block states), Fabric 26.3.
  2. Join any server; wait until the world is visible and move.
  3. The first block update after the join (a crop growing, a door, any ClientboundBlockUpdatePacket) runs the rebuild, 170-290 ms. Whether that lands as a visible freeze depends on whether the update arrives before or after the world becomes visible; in 4 rejoins the worst post-join frames were 243 / 176 / 38 / 47 ms (table below). The mixins involved are mixin.util.initialization (the reset) and mixin.util.block_tracking / mixin.ai.pathing (the lazy rebuild and what it fills).

Frame times, worst frame in the first seconds after a rejoin (PresentMon), 4 rejoins each:

build worst frames (ms)
Lithium 0.26.3 as released 243, 176, 38, 47
with the block info rebuilt eagerly after tags are applied (see below) 55, 53, 46, 58

(The 176 ms case was a ZGC allocation stall on the render thread, not this code path.)

Suggested fix

Rebuild eagerly instead of lazily: after the pending block tags are bound (the end of tag application for the block registry, i.e. after PendingTags.apply / bindTags, not in the prepareTagReload hook, which runs before the new tags are in place), call BlockInfoInitializer.initializeBlockInfo() right away. On the client that moves the 170-290 ms into the Connecting/loading screen, where it is invisible; the next lithium$getAllFlags() then finds the flags ready. We run exactly that as a small local patch: the rebuild took 170-292 ms on the Connecting screen, join time was unchanged (4.3-5.3 s vs 4.6-5.0 s), and the in-world frame was gone (table above). The same lazy rebuild exists on a dedicated server after /reload (first block change after the reload pays it on the server thread); we did not measure that side.

Other Information

Large Fabric pack (~430 mods), list on request. No crash, no log output from Lithium; the evidence is the JFR stack above. Happy to test a branch.

Activity

  1. 2No2Name commented on Nov 20, 2026

    @2No2Name
    Member

    This doesn't require any other mods. With just lithium the highest frame time after rejoin is about 30-60ms on my machine.
    Your suggested fix seems plausible. Consider posting your code.

  2. added
    S-confirmed
    on Nov 20, 2026
  3. D3M0NQTR commented on Nov 20, 2026

    @D3M0NQTR
    Author

    Here it is. It's a small client-only mixin in a separate helper mod, which is why it calls Lithium by reflection; inside Lithium the body would just be BlockInfoInitializer.initializeBlockInfo();. Trimmed (logging and timing removed, names changed), feel free to use it:

    @Mixin(targets = "net.minecraft.client.multiplayer.RegistryDataCollector")
    public abstract class CollectRegistriesMixin {
        @Unique private static Method initBlockInfo;
        @Unique private static boolean failed;
    
        // collectGameRegistries applies the server's tags (loadNewElementsAndTags -> PendingTags.apply)
        // during the configuration phase, i.e. while the Connecting screen is still shown.
        @Inject(method = "collectGameRegistries", at = @At("RETURN"))
        private void initBlockInfoAfterTags(CallbackInfoReturnable<RegistryAccess.Frozen> cir) {
            if (failed) return;
            try {
                if (initBlockInfo == null) {
                    initBlockInfo = Class.forName("net.caffeinemc.mods.lithium.common.initialization.BlockInfoInitializer")
                            .getMethod("initializeBlockInfo");
                }
                initBlockInfo.invoke(null);
            } catch (Throwable e) {
                failed = true; // keep Lithium's lazy init
            }
        }
    }

    Lithium's own reset in prepareTagReload stays as it is; this only rebuilds right after the new tags are bound, so the first in-world lithium$getAllFlags() finds the flags ready. The "rebuilt eagerly" numbers in the table above are with exactly this. We only measured multiplayer (re)joins; the dedicated-server /reload path is not covered by it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-confirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions