Repository navigation
Center the install dashboard's text without subshells - #296
Closed
namespaceMarcello wants to merge 1 commit into
Closed
namespaceMarcello wants to merge 1 commit into
namespaceMarcello wants to merge 1 commit into
Conversation
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>
Collaborator
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 | sedto strip the colour sequences, andstty. It now starts one, forstty, 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_lenstrips the sequences with bash's=~and setsVISIBLE_LEN.=~uses glibc's regex, the same oneseduses, so the ranges read the same in every locale. Text with a backslash or a newline keepsprintf '%b' | sed, since%bcan produce a NUL and$(...)drops trailing newlines.measure_paddingsetsPADDINGfrom onestty sizeper call (execinside$(...)saves the extra fork bash makes for a redirected command);left_paddingandcenteruse 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.quattroare the same with or without this.Validation:
test/unit/install-dashboard-center-test.sh: the exact bytescenter()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 startssttyonce and nothing else. Onquattrothe byte checks pass and the last check fails onsed.centercall 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 withsttyfailing; 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 asquattro'ssedin all three locales../test/all: the shell tests pass on both trees, includinginstall-media-diagnosis-test.sh, which runs the whole dashboard under a pty. The Python suite shows the same 12test_keyboarderrors on both, fromlocalectlneeding systemd as PID 1, which our container did not boot.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