Skip to content

perf(player): write auth input flags without copying the enum - #512

Merged
RaphiMC merged 1 commit into
ViaVersionAddons:mainfrom
StackAnvil:stackanvil/0208-write-auth-input-flags-without-copying-the-enum
Dec 3, 2026
Merged

RaphiMC merged 1 commit into
ViaVersionAddons:mainfrom
StackAnvil:stackanvil/0208-write-auth-input-flags-without-copying-the-enum

Conversation

@AlexProgrammerDE

Copy link
Copy Markdown
Collaborator

What this changes

The PlayerAuthInput translation runs every client tick. It walked
PlayerAuthInputData.values(), which allocates a copy of all 66 constants,
and checked each one against the player's input set.

The input set is an EnumSet, which iterates in declaration order, so
iterating it directly writes the same flags in the same order. This
removes the array copy and the 66 membership checks per tick.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

This PR contains one patch from StackAnvil's viabedrock stack, applied alone to the pinned upstream base.

Test sources, fixtures, and test-only build configuration stay in StackAnvil's local stack and are excluded from this PR.

Write auth input flags without copying the enum

Design constraint

The packet must keep its layout.
EnumSet iteration follows declaration order, so the new loop writes the same flag count and the same flag values in the same order as the old one.

Validation

  • The patch applies to the pinned upstream base without StackAnvil setup, and the upstream build passes.
  • The full StackAnvil stack builds with this change. Its player input, prediction, and teleport tests pass.

Limits

I found this by reading the code, not by profiling. It removes one array allocation per tick and does not change behavior.

🤖 Generated with Claude Code

The PlayerAuthInput translation runs every client tick. It walked
PlayerAuthInputData.values(), which allocates a copy of all 66 constants,
and checked each one against the player's input set.

The input set is an EnumSet, which iterates in declaration order, so
iterating it directly writes the same flags in the same order. This
removes the array copy and the 66 membership checks per tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Exterminate5573

Copy link
Copy Markdown
Collaborator

Looks fine @RaphiMC what do you think

@AlexProgrammerDE
AlexProgrammerDE marked this pull request as ready for review December 3, 2026 10:11
@RaphiMC
RaphiMC merged commit 07d06d7 into ViaVersionAddons:main Dec 3, 2026
1 check passed
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.

3 participants