Make the settings screen redraw 50x faster
Arrow-key navigation took 435 ms per keypress, which reads as the whole console reloading on every press - because it effectively was. The cost was forks: each frame ran a command substitution per label for the value, the translation and the rendered state, 54 subshells for eighteen rows. The frame is now assembled in memory and written once. Translations, the split specs and the terminfo clear string are resolved before the loop; values are re-read only after something actually changes, not on cursor movement. Helpers on that path assign to a variable instead of printing, since printing is what forced the substitution. Measured on the same machine: 435 ms -> 7.5 ms per keypress.
This commit is contained in:
1 parent
c308b7e286
commit
2fa830284e
4 files changed
+111
-43
No files matched your search
+17
-8
@@ -20,11 +20,17 @@ _cau_config_slurp() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# cau_config_get <Key> [default]
|
||||
cau_config_get() {
|
||||
# _cau_config_lookup <Key> [default]
|
||||
# Result in CAU_CONFIG_VALUE. Assigning rather than printing matters on the
|
||||
# settings screen, which reads every key on every frame: a command substitution
|
||||
# there is a fork, and forks were the entire cost of a redraw.
|
||||
CAU_CONFIG_VALUE=''
|
||||
|
||||
_cau_config_lookup() {
|
||||
local key="$1" default="${2:-}" val='' line
|
||||
|
||||
[[ -r $CAU_CONFIG ]] || { printf '%s\n' "$default"; return; }
|
||||
CAU_CONFIG_VALUE="$default"
|
||||
[[ -r $CAU_CONFIG ]] || return 0
|
||||
_cau_config_slurp
|
||||
|
||||
# last assignment wins, matching the previous sed|tail behaviour
|
||||
@@ -41,11 +47,14 @@ cau_config_get() {
|
||||
val="${val%\"}"
|
||||
val="${val#\"}"
|
||||
|
||||
if [[ -n $val ]]; then
|
||||
printf '%s\n' "$val"
|
||||
else
|
||||
printf '%s\n' "$default"
|
||||
fi
|
||||
[[ -n $val ]] && CAU_CONFIG_VALUE="$val"
|
||||
return 0
|
||||
}
|
||||
|
||||
# cau_config_get <Key> [default]
|
||||
cau_config_get() {
|
||||
_cau_config_lookup "$@"
|
||||
printf '%s\n' "$CAU_CONFIG_VALUE"
|
||||
}
|
||||
|
||||
# cau_config_bool <Key> <default: yes|no>
|
||||
|
||||
Reference in new issue
Block a user