Skip to content

Resource use

Mike edited this page Oct 18, 2026 · 4 revisions

Resource use

Measured on 2026-10-18 with 0.7.2 on a desktop (Intel i7-11700, powersave governor; Hyprland, Ghostty, 7 terminals: 2 windows and 5 tmux panes). CPU is a share of one core. To repeat: make bench and bench/service.sh in the repository.

2026-10-18 (0.7.2) 2026-09-30
Memory of the process itself (PSS) 0.49–0.56 MB 0.46 MB
Memory as accounted by systemd (includes shared pages) 1.0–2.0 MB 1.3–2.6 MB
CPU, terminals fully quiet ~0.0005% (0.1 wakeups/s) not measured
CPU, a terminal printing continuously 0.045–0.053% 0.04–0.05%
CPU, a password prompt pending: plain terminal / tmux pane 0.05% / 0.11% ~0.1%
Wakeups per second: printing / prompt pending 5 / 15 5 / –
Delay before switching, terminal prompt in the focused window 9–19 ms, at times ~200 ms up to 50 / 200 ms
Delay before switching, password field (fcitx5 addon) 5–15 ms not measured
Binary / addon 150 KB / 96 KB 100 KB / –
Addon in fcitx5's memory (PSS) 96 KB of fcitx5's 19 MB not measured

While terminals are quiet nothing wakes the service on a timer: the wakeups come from Hyprland's event socket, which reports every window title change, focus move or layout switch; the service reads the event, sees no layout change and sleeps again (~45 µs). In a minute of browsing with no terminal output: 10 Hyprland events, 0 terminal events, 14 wakeups.

The ~200 ms delays are prompts that appeared while another terminal was printing: then the service checks every 200 ms. The 2026-09-30 "quiet" figure (~0.006%, 0.7 wakeups/s) was taken while some terminal still printed now and then. For comparison, the first version polled every terminal every 200 ms: 0.05–0.07% of a core even while nothing happened, 5 wakeups a second (still 116 µs per wakeup in 2026-10-18's bench/loop.cpp). A Python prototype before it used 9.9 MB.

Why it is built this way

One polling pass over 7 terminals costs about 100 µs, almost all of it in the first system calls after a sleep (2026-10-18: listing /dev/pts 39–46 µs, opening the terminals 32–40 µs, stat 16–21 µs, reading their modes 12–16 µs, closing them 13–18 µs); the same pass in a hot loop takes 9 µs. Hence: do not wake while terminals are quiet, and check only those that printed. Reading the whole process table takes about 1 ms, so it is read only when the focused window or the set of pending prompts changes. tmux is asked again only when the prompts, the focused window or a client's screen change, so a prompt in tmux costs no more than one in a plain terminal.

Method

  • CPU time and wakeups — bench/service.sh: the change in the first field of /proc/<pid>/schedstat and in voluntary_ctxt_switches over 20–40 s.
  • Polling, for comparison — bench/loop.cpp; one pass broken down — bench/pass.cpp (the ~3 µs cost of reading the clock subtracted).
  • Memory — MemoryCurrent of the unit and Pss from /proc/<pid>/smaps_rollup.
  • Delay — terminal: a Ghostty window that waits 0.7 s for focus, writes the time and runs read -s, against the service's journal entry "Latin for tty". Password field: from fcitx5's FocusIn over D-Bus (as tools/fake-field does) to the keyboard's layout changing in hyprctl devices, polled (each poll ~3 ms, so it overstates by a few ms).
  • Fully quiet — 60 s with nobody typing and no terminal printing.
  • Addon memory — Pss of libpasswordlayout.so's mappings in /proc/<fcitx5 pid>/smaps.

Wakeup costs vary with the CPU's state and the machines differ, so only figures measured together compare closely.

Clone this wiki locally