-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-07-31/02: add "Troubleshoting: terminal lag and solutions with N…
…ix" as draft
- Loading branch information
1 parent
783fca6
commit a4e0d5b
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
2024-07-31/.02-troubleshooting-terminal-lag-and-solutions-with-nix.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Troubleshoting: terminal lag and solutions with Nix | ||
|
||
Inspired by this [blog post from | ||
Tavis](https://lock.cmpxchg8b.com/slowterm.html), I decided to document my own | ||
recent journey of reducing terminal lag startup. This post is way less | ||
interesting than the one from Tavis that uses a debugger to patch applications | ||
on the fly, but should still be interesting for some. And it also shows how | ||
powerful Nix can be for some things. | ||
|
||
For context, I have basically 3 systems where I interact with terminal | ||
frequently: | ||
|
||
- Thinkpad P14s Gen 1 running NixOS, with a reasonable fast CPU and disk | ||
- [MacBook Pro "M1 | ||
Pro"](https://everymac.com/systems/apple/macbook_pro/specs/macbook-pro-m1-pro-10-core-cpu-16-core-gpu-16-2021-specs.html) | ||
(what an awful name scheme Apple) with a really fast CPU and disk, but of | ||
course running macOS | ||
+ Sadly this is being phased-out since this is a job owned machine and I am | ||
changing jobs right now, but will be replaced with another one soon™ | ||
- [Chromebook Duet | ||
3](https://chromeunboxed.com/lenovo-chromebook-duet-3-review-perfect-sequel) | ||
running ChromeOS, with slow CPU and disk | ||
|
||
My experience is similar to Tavis, at around 300ms of startup time I don't care | ||
too much, but around 500ms+ is where I start to notice. I never had any issues | ||
with startup time in NixOS itself (I had issues with macOS before, but it was | ||
not actually the fault of macOS), but in the Chromebook it was awful: 600ms+ | ||
with [hot | ||
start](https://www.instabug.com/blog/understanding-cold-hot-and-warm-app-launch-time), | ||
while cold start it could be multiple seconds. | ||
|
||
The shell that I used is ZSH, and we check how long it takes to start by using: | ||
|
||
``` | ||
$ time zsh -ci exit | ||
zsh -ic exit 0.04s user 0.10s system 100% cpu 0.143 total | ||
``` | ||
|
||
The `-i` flag here is important, because we are interested in the interactive | ||
use of ZSH. Without this flag ZSH will ignore your `~/.zshrc` file, and the | ||
results will be meaningless. | ||
|
||
To do a more interesting benchmark, we can use [`hyperfine`](https://github.com/sharkdp/hyperfine): | ||
|
||
``` | ||
$ hyperfine "zsh -ic exit" | ||
Benchmark 1: zsh -ic exit | ||
Time (mean ± σ): 145.4 ms ± 4.2 ms [User: 49.8 ms, System: 97.3 ms] | ||
Range (min … max): 138.6 ms … 155.3 ms 19 runs | ||
``` | ||
|
||
Hyperfine will run the command multiple times and take care of things like | ||
shell startup time. A really great tool to have in your toolbox by the way, but | ||
I digress. |