Skip to content

Architectury API

BonsUnleashed edited this page Oct 7, 2026 · 3 revisions

Architectury API

Minecraft 1.20.1 / Forge: this page documents that build and its measurements. For the separate 170-control Minecraft 1.21.1 port, see Minecraft 1.21.1 NeoForge.

One control for Architectury API 9.2.14 (mod id architectury): events are dispatched with a plain reflective call instead of resolving a method handle again each time. Architectury is a shared library, so a saving per call is multiplied by every mod that uses it. The switch checks the code it would change against the tested build; another build is left untouched with one WARN line (see How the patches are applied).

Key Target Side Since Kind Result
architectury_event_dispatch Architectury API 9.2.14 BOTH 1.0.2 opt 19× faster dispatch

architectury_event_dispatch

Since: 1.0.2 · Script (1.0.19 and earlier): bons_and_furious-EventFactory.js Patched: dev.architectury.event.EventFactory.invokeMethod Mixin (since 1.0.20): EventFactoryMixin

What upstream did. Architectury dispatches every listener call through MethodHandles.lookup().unreflect(method).bindTo(listener).invokeWithArguments(args) — re-resolving a MethodHandle for every listener on every event, with no cache. In the reference pack the server tick alone fires this about 73,000 times per second (34 dimensions × 54 LevelTick subscribers × 2 phases × 20 tps), and Spark attributed 4.9–10.5 % of server-thread time to this dispatch.

What the patch does. Calls method.invoke(listener, args) directly. Method.invoke's cached accessor makes the call fast on Java 17/21 without any handle cache of its own. InvocationTargetException is unwrapped so the listener's own exception is rethrown unchanged.

What stays the same. Listener order, arguments and exception behaviour are identical.

With Collections Of Optimizations (tested 4.4, since 1.0.27). Its option architectury.directEventDispatch makes the same change. While that option is on, this control steps aside; while it is off, this control applies and leaves COO's copy out, so only one copy runs. See Compatibility and target versions.

Measured. 649 → 34 ns per invocation (19×) in a 2,000,000-call JDK 17 harness. After installation, the client render-thread share of Architectury dispatch measured 0.39 %.

Bons and Furious

Minecraft 1.20.1 / Forge 1.0.34

Compatibility

Controls by mod

Links

Clone this wiki locally