perf(controller): skip customization work when no input is active - #999
Open
Endymi0n74 wants to merge 1 commit into
Open
perf(controller): skip customization work when no input is active#999Endymi0n74 wants to merge 1 commit into
Endymi0n74 wants to merge 1 commit into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
pressedButtons,releasedButtons),This adds an
anyInputguard before the mapping work:currentGamepad.buttonsfor any pressed state (a button can be pressed while the sticks are centered and the triggers at rest);Why it's safe
shareButtonPressedis part of the guard itself, and theCAPTURE_SCREENSHOTdispatch stays outside the guarded block.Measurement
Hot-loop harness on a real session, controller at rest (idle):
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
pollGamepadcrash reported in #991 but does not change crash behavior — that one deserves its own fix (guardingbuttons[...]), which I can prepare separately if you're interested.