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