Bug 217742

Summary: HIDGamepadProvider adds an extra 50ms to all inputs
Product: WebKit Reporter: Justin Uberti <juberti>
Component: UI EventsAssignee: Brady Eidson <beidson>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, beidson, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: Mac   
OS: macOS 10.15   
Attachments:
Description Flags
Patch none

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].