Skip to content

perf(controller): skip customization work when no input is active - #999

Open
Endymi0n74 wants to merge 1 commit into
redphx:typescriptfrom
Endymi0n74:feat/controller-skip-idle
Open

perf(controller): skip customization work when no input is active#999
Endymi0n74 wants to merge 1 commit into
redphx:typescriptfrom
Endymi0n74:feat/controller-skip-idle

Conversation

@Endymi0n74

Copy link
Copy Markdown

What

The controller customization patch (button mapping, stick deadzones, trigger ranges) runs on every gamepad poll — up to 120 Hz at the default polling rate. When the controller is idle (no button pressed, sticks centered, triggers at rest), the block still:

  • allocates 2 objects (pressedButtons, releasedButtons),
  • iterates the entire mapping,
  • and runs the range/deadzone math for nothing.

This adds an anyInput guard before the mapping work:

  1. quick checks: Share button, both stick axes, both triggers;
  2. fallback: scan the raw currentGamepad.buttons for any pressed state (a button can be pressed while the sticks are centered and the triggers at rest);
  3. only then run the mapping work.

Why it's safe

  • When any input is active the behavior is bit-for-bit identical (the guard is pure fast-path).
  • The Share-button screenshot shortcut is untouched: shareButtonPressed is part of the guard itself, and the CAPTURE_SCREENSHOT dispatch stays outside the guarded block.
  • Zero behavioral change for configured mappings — only the idle case skips work.

Measurement

Hot-loop harness on a real session, controller at rest (idle):

Case Before After Δ
Controller customization (idle poll) 327 ns 34 ns ×9.5

Same machine, same seeds, median of passes. The speedup only applies while idle — during active input the cost is unchanged by design.

Note

This is a pure hot-path optimization. It lives in the same area as the pollGamepad crash reported in #991 but does not change crash behavior — that one deserves its own fix (guarding buttons[...]), which I can prepare separately if you're interested.

… active

The controller customization patch (mapping, deadzones, ranges) runs on
every gamepad poll (up to 120 Hz). When the controller is idle (no
button pressed, sticks centered, triggers at rest) the block still
allocates 2 objects and iterates the whole mapping for nothing.

Add an `anyInput` guard before the mapping work: share button, stick
axes and trigger values are checked first, then the raw button states
as a fallback (a button can be pressed while the sticks are centered).

Measured on the fork build (hot loop harness, idle controller):
327 ns → 34 ns per poll (~9.5x). Behavior is unchanged when any input
is active, including the Share button screenshot shortcut.

Closes nothing — this is a pure hot-path optimization.
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