Troubleshooting: Terminal Lag
Tavis Ormandy addresses slow xterm performance on Windows, identifying a window fading effect as a key issue. He implements a caching solution, reducing startup time to approximately 366ms, comparable to Fedora.
Read original articleTavis Ormandy discusses troubleshooting slow xterm performance on Windows compared to Fedora Linux. He notes that while xterm opens in about 300ms on Fedora, it takes approximately 1600ms on Windows, primarily due to a window fading effect that adds around 200ms to the startup time. Ormandy identifies that the X410 server is responsible for this animation, which he cannot disable. By using a debugger to modify the behavior of the window attributes, he reduces the delay significantly.
Further analysis reveals that filesystem performance under WSL is not the issue, as it performs slightly faster on Windows. He investigates various components, including the X server and font loading times, concluding that the toolbar feature in xterm, enabled on Windows but disabled on Fedora, contributes to the delay. After experimenting with various xterm settings, he finds a combination that improves startup time by about 200ms.
Ultimately, Ormandy implements a caching solution using deferred mapping to keep xterm processes running in the background, which allows for near-instant terminal access. This adjustment reduces the startup time to about 366ms, making it comparable to Fedora's performance. He expresses satisfaction with the solution, although he acknowledges that it may not be widely applicable to others.
Related
X debut 40 years ago (1984)
Robert W. Scheifler introduced the X window system in June 1984 for the VS100 Unix server, offering improved performance over W. The system was stable, with the Laboratory for Computer Science already transitioning to X and developing applications. Scheifler encouraged experimentation and welcomed volunteers for documentation contributions.
Four lines of code it was four lines of code
The programmer resolved a CPU utilization issue by removing unnecessary Unix domain socket code from a TCP and TLS service handler. This debugging process emphasized meticulous code review and system interaction understanding.
X Window System at 40
The X Window System, released in 1984 by Bob Scheifler, celebrated its 40th anniversary. It evolved into X11 in 1987, gaining popularity for its open-source nature and compatibility with existing applications. Reflecting on its impact, commentators highlight its resilience and continued relevance.
X Window System at 40
The X Window System, originating in 1984, celebrated its 40th anniversary. Key points include its evolution, open-source nature, and debates on successors like Wayland. Its lasting impact on computing environments is acknowledged.
Iconography of the X Window System: The Boot Stipple
The article explores the iconic stipple pattern in the X Window System's boot-up screen, symbolizing system evolution and complexity. It discusses its historical significance, disappearance from modern Linux distributions, and efforts for reintroduction.
- Several users express curiosity and appreciation for learning new debugging techniques and tools, such as the Microsoft Console Debugger and `hyperfine`.
- There is a consensus that while the reduced startup time of 366ms is an improvement, it still feels slow to some users, lacking a "snappy" experience.
- Some commenters share their own performance measurements and methodologies, highlighting variations in terminal startup times across different setups.
- Discussion includes the broader implications of UI latency across various devices, emphasizing a desire for more responsive applications.
- Users reflect on the value of optimizing performance, considering the cumulative time savings over years of usage.
"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...
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.
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.
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!
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
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...
Great debugging work to come up with a solution!
$ 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
Related
X debut 40 years ago (1984)
Robert W. Scheifler introduced the X window system in June 1984 for the VS100 Unix server, offering improved performance over W. The system was stable, with the Laboratory for Computer Science already transitioning to X and developing applications. Scheifler encouraged experimentation and welcomed volunteers for documentation contributions.
Four lines of code it was four lines of code
The programmer resolved a CPU utilization issue by removing unnecessary Unix domain socket code from a TCP and TLS service handler. This debugging process emphasized meticulous code review and system interaction understanding.
X Window System at 40
The X Window System, released in 1984 by Bob Scheifler, celebrated its 40th anniversary. It evolved into X11 in 1987, gaining popularity for its open-source nature and compatibility with existing applications. Reflecting on its impact, commentators highlight its resilience and continued relevance.
X Window System at 40
The X Window System, originating in 1984, celebrated its 40th anniversary. Key points include its evolution, open-source nature, and debates on successors like Wayland. Its lasting impact on computing environments is acknowledged.
Iconography of the X Window System: The Boot Stipple
The article explores the iconic stipple pattern in the X Window System's boot-up screen, symbolizing system evolution and complexity. It discusses its historical significance, disappearance from modern Linux distributions, and efforts for reintroduction.