Skip to content

Center the install dashboard's text without subshells - #296

Closed
namespaceMarcello wants to merge 1 commit into
omacom:quattrofrom
namespaceMarcello:perf/dashboard-center-builtins
Closed

namespaceMarcello wants to merge 1 commit into
omacom:quattrofrom
namespaceMarcello:perf/dashboard-center-builtins

Conversation

@namespaceMarcello

Copy link
Copy Markdown

Summary

The install dashboard's center() runs three times a frame, ten frames a second, for the whole install, and each call started eight processes: subshells for the visible length and the console width, printf | sed to strip the colour sequences, and stty. It now starts one, for stty, and prints the same bytes. Measured in an Arch container on our machine, the dashboard's CPU over 20 seconds goes from 3.62 to 2.14 CPU-seconds (18% to 11% of a core), and its cost per frame from 25 to 13 ms, while pacstrap runs on the same cores.

  • visible_len strips the sequences with bash's =~ and sets VISIBLE_LEN. =~ uses glibc's regex, the same one sed uses, so the ranges read the same in every locale. Text with a backslash or a newline keeps printf '%b' | sed, since %b can produce a NUL and $(...) drops trailing newlines.
  • measure_padding sets PADDING from one stty size per call (exec inside $(...) saves the extra fork bash makes for a redirected command); left_padding and center use it. The size is still read on every call: reading it once per frame would leave the failure and finish screens centered on an old size after a later resize.
  • Only these helpers change. The frame loop, the resize check and every call site are untouched, so this stays clear of Animate ISO installation with a work-driven Omarchy snake (#2) #199 and Omi in the install dashboard #292: Omi in the install dashboard #292 applies cleanly on top, and Animate ISO installation with a work-driven Omarchy snake (#2) #199's conflicts with quattro are the same with or without this.

Validation:

  • New test/unit/install-dashboard-center-test.sh: the exact bytes center() prints in 11 cases (colours, wide and narrow consoles, an unreadable size, UTF-8 and C locales, CSI and OSC sequences, text with backslashes), and that it starts stty once and nothing else. On quattro the byte checks pass and the last check fails on sed.
  • Old against new, byte for byte, 28 comparisons with no difference: every center call the dashboard makes with real values (1006 calls), plus 162 edge cases and 6000 fuzzed ones, in C.UTF-8 (the ISO's locale), en_US.UTF-8 and C, at 0, 20, 80 and 120 columns and with stty failing; and on a real pty at 33, 80 and 120 columns. Every Unicode code point placed in the escape's positions gives the same result as quattro's sed in all three locales.
  • ./test/all: the shell tests pass on both trees, including install-media-diagnosis-test.sh, which runs the whole dashboard under a pty. The Python suite shows the same 12 test_keyboard errors on both, from localectl needing systemd as PID 1, which our container did not boot.
  • Measurement: three 20-second runs per variant, interleaved; median 3.62 (3.55–3.84) against 2.14 (2.01–2.20) CPU-seconds. Processes per frame, under strace: 33.8 to 12.7.

Left for later, because it sits in render_dynamic, which #199 and #292 rewrite: the frame redraws the percentage, whimsy and tip lines ten times a second even when none changed (the whimsy turns every 4 s, the tip every 8 s), and the frame still runs $(term_size) and two subshells for the whimsy and tip. Skipping unchanged redraws would remove most of what remains.

Risk: if the new length differed from the old one for some text, that line would sit a column or two off center; none of the comparisons above found such a text. Reverting the commit undoes it.

Not checked: a real Linux console and how it looks there, and timings on hardware during an install.

Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work.

🤖 Generated with Claude Code

center() runs three times a frame, ten frames a second, for the whole
install. Each call started eight processes: a subshell for the visible
length, a printf | sed pipeline to strip the colour sequences, and
three subshells around stty for the console width, while pacstrap
competes for the same cores.

The visible length now strips the sequences with bash's =~, which uses
the same glibc regex as sed, and the padding is set in a variable
instead of printed into a subshell. Text with a backslash or a newline
keeps the printf | sed path, since %b can produce a NUL and $(...)
drops trailing newlines. The console size is still read on every call,
now with one fork for stty, so every line is centered on the size the
console has at that moment, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh

dhh commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded by #371 (which moved the 10 Hz animation loop to progress-icon.sh so center() no longer runs per frame) and #434/#461 (which updated visible_len() to use CJK-aware display_width).

@dhh dhh closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants