Skip to content

Cut the per-connection overhead around idle player ticks - #26

Merged
GrowlyX merged 1 commit into
masterfrom
perf/idle-packet-direct-handles
Nov 14, 2026
Merged

GrowlyX merged 1 commit into
masterfrom
perf/idle-packet-direct-handles

Conversation

@GrowlyX

@GrowlyX GrowlyX commented Nov 14, 2026

Copy link
Copy Markdown

Trims the per-connection work around Via's idle player ticks, which run every tick on the server's main thread.

Evidence

A 90 s JFR of legacy-fluid's main thread (2026-11-14, 422 players, arch.11) put IdlePacketTask.run at 15.6% of main-thread samples. By source line (222 samples):

Where Samples
the flying handler inside sendPlayer (the player tick itself) 173 unchanged; this is the 1.8 tick a 1.9+ idle client needs
connection.get(MovementTracker.class) for every connection 19 unchanged
iterating the connection list 14 unchanged
Bukkit.getPlayer 6 unchanged
Field.get(playerConnection) 5 method handle now
getProviders().get(...) per due connection 2 once per run now
the extra MovementTracker lookups in sendPlayer 1 removed

Change

  • IdlePacketTask: resolves the transmitter and reads System.currentTimeMillis() once per run, and passes the tracker it already looked up through a new MovementTransmitterProvider.sendPlayer(UserConnection, MovementTracker). Its default implementation delegates to the existing method.
  • BukkitViaMovementTransmitter: calls getHandle, the playerConnection field and PlayerConnection#a(PacketPlayInFlying) through method handles resolved once, in PlayerTicker.
  • Failures: anything the tick throws is still logged rather than thrown. Method#invoke used to wrap it, and through handles it would otherwise escape the task's loop over the remaining connections.
  • Packet mode (nms-player-ticking: false) is unchanged.

Expected effect

Small. The rows this touches add up to about 8 of the 1,423 main-thread samples (≈0.6%). A synthetic benchmark (450 stand-in players, JDK 25) puts the reflective calls at 19.2 ns per player against 17.5 ns through the handles: JDK 25's Method#invoke is already handle-based, so most of the remaining overhead is the per-connection lookup and iteration, which this leaves alone.

Testing

BukkitIdlePlayerTickerTest binds the ticker to stand-in classes with the NMS shapes. It checks the packet reaches the connection and the tracker advances, a missing connection is skipped without advancing, and a failing tick or a non-player object is reported to the failure sink instead of thrown. :viaversion-common:test and :viaversion-bukkit:test: 126 tests pass.

Not deployed or measured in production.

🤖 Generated with Claude Code

IdlePacketTask runs every tick on the main thread over every connection.
It now resolves the movement transmitter and reads the clock once per run,
and passes the MovementTracker it already looked up to the transmitter,
which used to look it up twice more. The Bukkit transmitter calls
getHandle, the playerConnection field and the flying handler through
method handles resolved once.

A failure inside the tick is still logged rather than thrown: Method#invoke
wrapped it before, and the handles would otherwise let it escape the
task's loop over the remaining connections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GrowlyX
GrowlyX merged commit d74ae6c into master Nov 14, 2026
2 of 3 checks passed
@loopyreviews-bot

Copy link
Copy Markdown

Loopy review

Confidence: 5/5 — No open findings.

Reviewed 4 of 4 changed files.

Trims per-connection overhead in Via's idle player ticking for 1.8 servers. IdlePacketTask now resolves the MovementTransmitterProvider and the current time once per run and passes the already-looked-up MovementTracker through a new two-arg sendPlayer overload whose default delegates to the existing one-arg method. On Bukkit, the NMS path now goes through a new PlayerTicker that resolves getHandle, the playerConnection field, and PlayerConnection#a(PacketPlayInFlying) once as method handles adapted to (Object)Object/(Object,Object)void signatures, and routes any failure from the tick to a logging sink instead of letting it escape into the task loop. Notable changes:

  • New MovementTransmitterProvider.sendPlayer(UserConnection, MovementTracker) overload; existing one-arg callers and subclass overrides keep working through delegation.
  • BukkitViaMovementTransmitter packet mode (nms-player-ticking: false) behavior is unchanged.
  • New BukkitIdlePlayerTickerTest covering packet delivery plus tracker advancement, missing-connection skip, failing tick reporting, and non-player reporting.

Reviews: 1 · last reviewed 8e8df55 · harness muse/muse-wonder-1.0 · Reply @loopyreviews-bot review to re-run · @loopyreviews-bot remember <rule> to teach Loopy

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant