Skip to content

CHANGE: ISX-2322 Rely on module (and platform) to manage polling frequency. #2200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 20, 2025

Conversation

ekcoh
Copy link
Collaborator

@ekcoh ekcoh commented Jul 3, 2025

Description

Removes polling frequency as a property being managed by InputManager and instead delegates life-time and initial setting to be configured by platform and input-module. This requires a specific Unity branch, see internal issue ISX-2322.

Also removed double-booking of pollingFrequency field from serialised state since I cannot see any reason to have it part of serialised state. Since property is now in native it won't be subject to domain reloads.

.asmdef files guarding for the underlying functionality has been set to 6000.3.0a6 which contains the required functionality.

Testing status & QA

Tested on macOS by setting native polling frequency to 123 Hz with a custom local build during development.
Recommended to test on Windows with Xbox gamepad on the associated Unity branch since Windows has a higher default than 60 Hz on that branch which affects the Windows Gaming Input backend. E.g. testing with a DualSense on Windows wouldn't make much difference since DualSense is using unconstrained polling at the platform level and do not depend on polling frequency setting.

Tested on macOS by seeing that default polling frequency is set to 60 Hz. However, this doesn't matter given the current backend implementations which do not rely on this but use underlying frameworks that are uncorrelated to it.
Tested on Windows with an Xbox gamepad which is currently one of the few ways to actually hit the associated functionality. Out of the box the target frequency is now 1000 Hz on Windows. But as can be seen in Input Debugger the polling frequency saturates as 125 Hz which is the maximum for an Xbox gamepad. Changing target to e.g. 200 Hz still produces 125 Hz. This is expected. Setting it lower, e.g. 60 Hz however rate-limits the polling frequency in the backend to this frequency. See screenshots below. Not that DualSense on Windows runs at "infinite frequency" so it would just yield saturated max frequency regardless this setting and this makes that device unfit for testing.

PollingFrequencyDefault PollingFrequencyCustomFreq PollingFrequencyCustom2

Overall Product Risks

Small.

  • Complexity: Small
  • Halo Effect: Small

Comments to reviewers

Note that this branch should be merged after the corresponding Unity feature branch has landed since version is otherwise unknown: update changeling, comments and asmdef condition

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Devices_PollingFrequencyIsAtLeast60HzByDefault conditionally replaces Devices_PollingFrequencyIs60HzByDefault conditionally based on Unity version being used.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@ekcoh ekcoh changed the title CHANGE: Rely to module to manage polling frequency. CHANGE: ISX-2322 Rely to module to manage polling frequency. Jul 3, 2025
@ekcoh ekcoh marked this pull request as ready for review July 3, 2025 12:30
@ekcoh ekcoh requested review from Pauliusd01 and jfreire-unity July 3, 2025 12:31
@codecov-github-com
Copy link

codecov-github-com bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

@@           Coverage Diff            @@
##           develop    #2200   +/-   ##
========================================
  Coverage    68.11%   68.11%           
========================================
  Files          367      367           
  Lines        53633    53638    +5     
========================================
+ Hits         36530    36535    +5     
  Misses       17103    17103           
Flag Coverage Δ
linux_2021.3_pkg 5.46% <0.00%> (-0.01%) ⬇️
linux_2021.3_project 70.37% <100.00%> (+<0.01%) ⬆️
linux_2022.3_pkg 5.23% <0.00%> (-0.01%) ⬇️
linux_2022.3_project 65.21% <100.00%> (+<0.01%) ⬆️
linux_6000.0_pkg 5.24% <0.00%> (-0.01%) ⬇️
linux_6000.0_project 68.01% <100.00%> (+0.04%) ⬆️
linux_6000.1_pkg 5.24% <0.00%> (-0.01%) ⬇️
linux_6000.1_project 67.97% <100.00%> (+<0.01%) ⬆️
linux_6000.2_pkg 5.24% <0.00%> (-0.01%) ⬇️
linux_6000.2_project 68.00% <100.00%> (+<0.01%) ⬆️
linux_trunk_pkg 5.24% <0.00%> (+<0.01%) ⬆️
linux_trunk_project 68.00% <100.00%> (+<0.01%) ⬆️
mac_2021.3_pkg 5.45% <0.00%> (-0.01%) ⬇️
mac_2021.3_project 70.38% <100.00%> (+<0.01%) ⬆️
mac_2022.3_pkg 5.22% <0.00%> (-0.01%) ⬇️
mac_2022.3_project 65.24% <100.00%> (+<0.01%) ⬆️
mac_6000.0_pkg 5.23% <0.00%> (-0.01%) ⬇️
mac_6000.0_project 68.03% <100.00%> (+<0.01%) ⬆️
mac_6000.1_pkg 5.23% <0.00%> (-0.01%) ⬇️
mac_6000.1_project 68.03% <100.00%> (-0.02%) ⬇️
mac_6000.2_pkg 5.23% <0.00%> (-0.01%) ⬇️
mac_6000.2_project 68.03% <100.00%> (+<0.01%) ⬆️
mac_trunk_pkg 5.23% <0.00%> (+<0.01%) ⬆️
mac_trunk_project 68.03% <100.00%> (+<0.01%) ⬆️
win_2021.3_pkg 5.45% <0.00%> (-0.01%) ⬇️
win_2021.3_project 70.45% <100.00%> (+<0.01%) ⬆️
win_2022.3_pkg 5.23% <0.00%> (-0.01%) ⬇️
win_2022.3_project 65.31% <100.00%> (+<0.01%) ⬆️
win_6000.0_pkg 5.24% <0.00%> (-0.01%) ⬇️
win_6000.0_project 68.10% <100.00%> (-0.01%) ⬇️
win_6000.1_pkg 5.24% <0.00%> (-0.01%) ⬇️
win_6000.1_project 68.10% <100.00%> (-0.01%) ⬇️
win_6000.2_pkg 5.24% <0.00%> (-0.01%) ⬇️
win_6000.2_project 68.10% <100.00%> (+<0.01%) ⬆️
win_trunk_pkg 5.24% <0.00%> (+<0.01%) ⬆️
win_trunk_project 68.10% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../com.unity.inputsystem/InputSystem/InputManager.cs 88.72% <100.00%> (+0.02%) ⬆️
...s/com.unity.inputsystem/InputSystem/InputSystem.cs 82.96% <ø> (ø)
...nity.inputsystem/InputSystem/NativeInputRuntime.cs 45.40% <100.00%> (+0.27%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ekcoh ekcoh changed the title CHANGE: ISX-2322 Rely to module to manage polling frequency. CHANGE: ISX-2322 Rely on module to manage polling frequency. Jul 3, 2025
@ekcoh
Copy link
Collaborator Author

ekcoh commented Jul 4, 2025

Looks like asmdef condition is true for trunk which it shouldn't be, will make sure related Unity PR is on-par with trunk investigate.

… contain required changes. Note that to test one has to weak this asmdef.
@ekcoh
Copy link
Collaborator Author

ekcoh commented Jul 4, 2025

As suspected trunk had advanced hence asmdef is now a3 to exclude trunk. Note that during testing you have to modify the asmdef to be a2 when tested with the corresponding Unity branch.

Copy link
Collaborator

@jfreire-unity jfreire-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Added a comment of something that would be relevant to have IMO.

Comment on lines +4400 to +4403
public void Devices_PollingFrequencyIsAtLeast60HzByDefault()
{
Assert.That(InputSystem.pollingFrequency, Is.GreaterThanOrEqualTo(60));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also run this test when we check XInput on Windows? I'm not sure if its ideal to do this on the package but I'd like to test that this pollingFrequency is at least affected by platforms that do expose it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a setting. The KPI branch on module "sampling performance" is testing exactly that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I also added the achievable frequency to input debugger long ago. If you set this to 250 you might get what the device and system conditions support. e.g. 125

@Pauliusd01
Copy link
Collaborator

Are these CI failures expected?

Reason(s): One or more scripts have failed to compile.
Detail(s): Message: Packages\com.unity.inputsystem\InputSystem\NativeInputRuntime.cs(215,38): error CS0117: 'NativeInputSystem' does not contain a definition for 'GetPolling

@Pauliusd01
Copy link
Collaborator

Doing the actual testing I genuinely didn't see any differences at all, the Input Debugger reports my Xbox Controller Polling Frequency as 60 Hz both when using trunk or the required editor PR. Nothing seemed broken or different at all in the actual gamepad scenes as well. So I felt like I must be checking things wrong or maybe that's fine? 🤷

Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just gonna update my status here. I do have concerns but if those turn out to be irrelevant I can approve

@ekcoh
Copy link
Collaborator Author

ekcoh commented Aug 12, 2025

Are these CI failures expected?

Reason(s): One or more scripts have failed to compile.
Detail(s): Message: Packages\com.unity.inputsystem\InputSystem\NativeInputRuntime.cs(215,38): error CS0117: 'NativeInputSystem' does not contain a definition for 'GetPolling

Compile errors are expected if the asmdef isn't matching the Unity version it got merged into. I will update this PR accordingly to match trunk.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Aug 13, 2025

Updated asmdef files to map to Unity version containing relevant functionality to support this. Seems however difficult to verify this on macOS at the moment since polling frequency seems to be ignored so need to revisit when I have access to a Windows machine where its more straightforward to verify this.

@ekcoh ekcoh changed the title CHANGE: ISX-2322 Rely on module to manage polling frequency. CHANGE: ISX-2322 Rely on module (and platform) to manage polling frequency. Aug 18, 2025
@ekcoh ekcoh requested a review from Pauliusd01 August 18, 2025 07:41
@ekcoh
Copy link
Collaborator Author

ekcoh commented Aug 18, 2025

I updated the description after my latest testing. I used the following script to change the polling frequency as part of entering play mode to verify:

using UnityEngine;
using UnityEngine.InputSystem;

public class PollingFrequency : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        InputSystem.pollingFrequency = 50.0f; // Change target polling frequency from default
    }
}```

@ekcoh
Copy link
Collaborator Author

ekcoh commented Aug 18, 2025

Fixed an issue in b4971d3 which caused a test to fail since the test runtime polling frequency wasn't initialized inline with valid value range. It is now initialized to 60 Hz which is the default.

@jfreire-unity
Copy link
Collaborator

jfreire-unity commented Aug 19, 2025

@Pauliusd01 sorry, I re-asked your review withouth knowing you add approved it 2h ago. feel freee to approve again!

Copy link
Collaborator

@jfreire-unity jfreire-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving. Thanks for the extra screenshots and defaults in the test runtime.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Aug 19, 2025

Thanks for review and testing, will merge this one as soon as CI has rerun.

@ekcoh ekcoh merged commit 775282e into develop Aug 20, 2025
134 checks passed
@ekcoh ekcoh deleted the isx-2322-polling-frequency branch August 20, 2025 06:44
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