Skip to content

WardEventHandler.onWorldTick() repeatedly calls Chunk.getCapability() every tick, avoidable per-tick capability lookup #423

Description

@BuenChico785446

Profiling shows WardEventHandler.onWorldTick() consuming ~1.24% of total server thread time, almost entirely inside Chunk.getCapability() → CapabilityDispatcher.getCapability() (~1.13%).

This appears to be a per-tick cost rather than a one-time cost, onWorldTick() runs every server tick, and each call re-fetches the ward capability from the chunk via Forge's generic CapabilityDispatcher lookup instead of caching a direct reference.

Image

Suggested fix:

  • Cache the ward capability reference for a chunk when the chunk is loaded (e.g. in a chunk-load event), rather than calling getCapability() fresh on every tick.

  • Alternatively, maintain a direct map/reference from chunk to its ward data structure, bypassing the generic Forge capability dispatch entirely for this hot path.

  • Consider skipping chunks with no active wards early, if a cheap way to check that exists, to avoid the capability lookup entirely for chunks that don't need it.

This is a repeating, always-on cost (unlike worldgen-only costs), so even a modest per-tick overhead compounds over time across all loaded chunks.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions