Bug 217742 - HIDGamepadProvider adds an extra 50ms to all inputs
Summary: HIDGamepadProvider adds an extra 50ms to all inputs
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 14
Hardware: Mac macOS 10.15
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-10-14 17:40 PDT by Justin Uberti
Modified: 2021-07-01 13:22 PDT (History)
3 users (show)

See Also:


Attachments
Patch (3.04 KB, patch)
2021-07-01 10:20 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Uberti 2020-10-14 17:40:31 PDT
When measuring Safari's button-to-photon latency with html5gamepad.com, I noticed that Safari has roughly double the latency of Chrome for wired USB gamepads (108ms vs 56ms).

I investigated this a bit and found this code in HIDGamepadProvider which I believe accounts for the difference:
https://github.com/WebKit/webkit/blob/950143da027e80924b4bb86defa8a3f21fd3fb1e/Source/WebCore/platform/gamepad/mac/HIDGamepadProvider.cpp#L39

50ms is enormous latency for a gamepad - gaming mice charge a premium in order to deliver ~10ms latency savings.

Could this delay be reduced or eliminated? The rationale around this code isn't entirely clear to me:

    // This isActive check is necessary as we want to delay input notifications from the time of the first input,
    // and not push the notification out on every subsequent input.
    if (!m_inputNotificationTimer.isActive())
        m_inputNotificationTimer.startOneShot(inputNotificationDelay);
Comment 1 Radar WebKit Bug Importer 2020-10-14 17:56:27 PDT
<rdar://problem/70315838>
Comment 2 Brady Eidson 2020-10-15 13:03:28 PDT
Definitely room for improvement here.
Comment 3 Justin Uberti 2020-10-23 10:26:25 PDT
Note also that GameControllerGamepadProvider also has a 16ms notification delay:
https://github.com/WebKit/webkit/blob/950143da027e80924b4bb86defa8a3f21fd3fb1e/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepadProvider.mm#L45

Could anyone comment on the intent behind these delays?
Comment 4 Brady Eidson 2021-07-01 10:20:28 PDT
Created attachment 432706 [details]
Patch
Comment 5 EWS 2021-07-01 13:22:29 PDT
Committed r279480 (239333@main): <https://commits.webkit.org/239333@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 432706 [details].