from Hacker News

Measuring keyboard-to-photon latency with a light sensor (2023)

by ossusermivami on 11/4/24, 6:16 PM with 12 comments

  • by fhars on 11/10/24, 9:08 AM

    So it looks like input latency on current hardware still has not quite caught up with the apple IIe, but is better that the PET 4016, so not all the hardware progress in the last seven yeas has been eaten by software: https://danluu.com/input-lag/
  • by schobi on 11/10/24, 8:14 AM

    I love that he openly discusses the paths he went wrong and how more accuracy could be found. Detection threshold from the sensor or avoiding accidental synchronization to the monitor are not obvious pitfalls. The mini ASCII histogram is something I need myself - nice thought!

    I remain puzzled on the goal. Does he optimize his setup for a good coding experience? (this should definitely include the actual keyboard in the measurements!) Is he optimizing editors? Picking a new monitor? As a learning excercise?

    I'm all for "because I can" as a valid reason, but that often leaves my projects dangling halfway complete. Are we there yet? Don't know - not sure where I want to be.

  • by ezconnect on 11/10/24, 11:18 AM

    He should have measured the latency on Facebook web messenger latency. I sometimes experience more than second even sometimes 2 secs per letter. Its amazing how can they make something so unusable on a very simple text input.
  • by Aachen on 11/10/24, 1:36 PM

    If someone wants to measure this latency without special hardware or code, check if your (friend's) smartphone has a 1000 fps mode. I'm not caught up with newer phones but my 2019 Samsung has this and I use it all the time to look at things that happen quickly.

    It just needs a lot of light (phone flashlight is sufficient at short range), or to emit light by itself like a screen (or microwave segment display, as a random example where you can see it lights up each digit individually and they're never all on at the same time, but we can't perceive that).

    Method:

    To measure, film the computer screen, positioning the phone in a way that it also captures the keyboard (best head on, since you're interested in when vertical movement stops). Press record, strike a key, and go frame by frame on the recording. The moment the key bottoms out is pretty clear by your finger stopping to move down (if the focus is good, you also see a ripple effect in your hand). I know the trigger point will be before the key's very bottom, but the whole key's travel time is on the order of 2-3 frames = ~2-3 ms, which is good enough for me. Then, count frames until the computer screen updates. I usually wait for all channels before considering it updated (my work laptop emits only red on a separate refresh cycle, sometimes noticeable if you look away with some lucky timing in the right way)

    Similarly for the mouse, though I usually pick it up and hold it in one hand before the screen and click the button in the air so that you can hold it in a good (for the camera) position more easily. By lifting your finger off the mouse button until the moment where you're going to press it, the separation is very well visible on camera and the moment of pressing quite exactly determinable

    Results:

    On the LUKS disk password prompt at boot, latency is about 19 ms on a laptop. It feels extremely fast, a little like it shows the asterisk before I've finished pressing the key. After booting the OS, in gnome-terminal I get 48 ms. Connecting an external screen and keyboard via a cheap USB hub, it grows to 62 ms. Finally, inside the virtual machines we're supposed to use for everything (because security), my input-to-photon latency is 134 ms. Guess I can see why that boot prompt feels like a time traveller compared to what I need to use all day long!

    On a different setup (a family member's iirc, running Windows) with an external monitor that has three gaming modes, called standard, fast, and faster, the latencies are 67, 67, and 62 ms. Pretty disappointing for a "low latency gaming" mode!

    ---

    Compared to the submission:

    > One source of latency users experience that my tester doesn’t measure is keyboard latency.

    The high speed camera method will include this, which is an advantage if you want to know how much latency your setup has, but doesn't help you in picking apart where the latency occurs

  • by taspeotis on 11/10/24, 11:54 AM

  • by a-dub on 11/10/24, 7:58 AM

    i'd consider using a signal generator (square waves), led and oscilloscope to characterize the response time of the sensor apparatus itself.