from Hacker News

Troubleshooting: Terminal Lag

by janvdberg on 7/30/24, 10:04 PM with 55 comments

  • by vijucat on 7/31/24, 4:26 AM

    Love such articles where I learn something new. cdb is completely new to me. It's apparently the Microsoft Console Debugger. For others like me who were wondering how `eb win32u!NtUserSetLayeredWindowAttributes c3` neutered the window animation:

    "By executing this command, you are effectively replacing the first byte of the `NtUserSetLayeredWindowAttributes` function with a `ret` instruction. This means that any call to `NtUserSetLayeredWindowAttributes` will immediately return without executing any of its original code. This can be used to bypass or disable the functionality of this function"

    (Thanks to GitHub Copilot for that)

    Also see https://learn.microsoft.com/en-us/windows-hardware/drivers/d...

  • by txdv on 7/31/24, 6:01 AM

    So the root cause of the slowness was not found, it was just circumvented by keeping 3 xterms open and just using hiding/showing them?
  • by aardshark on 7/31/24, 2:42 AM

    300ms for startup still sounds slow to me. Not ridiculously so, but it won't give that snappy feeling.
  • by pcthrowaway on 7/31/24, 5:58 AM

    > I’ve been using this configuration for a few days, so far it’s working great. I haven’t noticed any issues running it this way.

    The journey was very useful, even the destination may be pretty specific to your needs. The process of how to go about debugging minor annoyances like this is really hard to learn about.

  • by zokier on 7/31/24, 5:33 PM

    Just for fun I did film some video footage from my 60Hz monitor to see how quickly my terminal starts up. Seems like 2-3 frames to show up the terminal window, and 1-2 frames to show shell prompt. So 50 ms - 83 ms. This is with foot terminal on Sway.

    My very unscientific methodology was to run

        $ echo hello && foot
    
    in a terminal and measure the time between the hello text appearing and the new window appearing. Looking at my video, the time from physical key press to "hello" text appearing might be 20ish ms but that is less clear, so about 100 ms total from key press to shell prompt.

    This is pretty much completely untuned setup, I haven't done any tweaks to improve the figures. Enabling foot server might shave some milliseconds, but tbh I don't feel that's necessary.

    It'd be fun to do this with better camera, and also with better monitors. Idk how difficult it would be to mod in some LED to keyboard to capture the exact moment the key is activated, just trying to eyeball the key movement is not very precise.

  • by mberning on 7/31/24, 2:54 AM

    This is a tour de force on the type of curiosity it takes to be really successful with computers.
  • by abraae on 7/31/24, 1:58 AM

    I'm at the tail end of my career, so working on efficiency gains like this doesn't usually add up for me.

    However I was interested in knowing whether it does for the author.

    Assuming he/she does suffer this 1300 ms delay "hundreds" of times a day (let's say 200) and for the sake of argument they use their computer 300 days a year and have 20 years of such work ahead of them with this config, then this inefficiency will total 1300 x 200 x 300 x 20 / 1000 / 60 / 60 hours wasted during author's lifetime - some 430 hours.

    So well worth the effort to fix!

  • by jd3 on 7/31/24, 3:52 AM

    I'm so distracted by latency that I run my macOS with vsync disabled 24/7 (through Quartz Debug).

    When I used to use Windows 10+ years ago, I had decent luck using xming + cygwin + Cygwin/X + bblean to run xterm in a minimal latency/lag environment.

    I also launch Chrome/Spotify/Slack desktop using:

    $ open -a open -a Google\ Chrome --args --disable-gpu-vsync --disable-smooth-scrolling

  • by Borg3 on 7/31/24, 8:56 PM

    Very nice article, I love such debugging. I sometimes do it myself too.

    Anyway, this also made me think about general bloat we have in new OSes and programs. Im still on old OS running spinning rust and bash here starts instantly when cache is hot. I think GUI designers lost an engineer touch...

  • by aardshark on 7/31/24, 2:42 AM

    300ms for startup still sounds slow to me. Not ridiculously so, but it won't give that snappy feeling.
  • by tonymet on 7/31/24, 7:31 PM

    We need a community of those obsessed with responsive applications. UI latency irks me on every device. Not only computers and smart phones, but now TVs, refrigerators, cars all have atrocious UI latency.

    Great debugging work to come up with a solution!

  • by pikseladam on 7/30/24, 11:16 PM

    it was a fun read
  • by aftbit on 7/30/24, 11:38 PM

    Upvote just for teaching me about the existence of `hyperfine`.

        $ hyperfine 'alacritty -e true'
        Benchmark 1: alacritty -e true
          Time (mean ± σ):      84.1 ms ±   4.9 ms    [User: 40.1 ms, System: 30.8 ms]
          Range (min … max):    80.5 ms … 104.4 ms    32 runs
        
        $ hyperfine 'xterm -e true'
        Benchmark 1: xterm -e true
          Time (mean ± σ):      81.9 ms ±   2.6 ms    [User: 21.7 ms, System: 7.9 ms]
          Range (min … max):    74.9 ms …  87.1 ms    37 runs
        
        $ hyperfine 'wezterm -e true'
        Benchmark 1: wezterm -e true
          Time (mean ± σ):     211.7 ms ±  13.4 ms    [User: 41.4 ms, System: 60.0 ms]
          Range (min … max):   190.5 ms … 240.5 ms    15 runs