Skip to content

Optimize input/event and width hot paths#10

Merged
alganet merged 1 commit into
mainfrom
perf
Jun 13, 2026
Merged

Optimize input/event and width hot paths#10
alganet merged 1 commit into
mainfrom
perf

Conversation

@alganet

@alganet alganet commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Pure-shell perf work focused on the keystroke→event→redraw path, validated across bash/zsh/ksh93/mksh/busybox with byte-identical behavior.

  • ord.sh: make _tuish_ord fork-free for bytes >=128. The old non-ASCII fallback forked $(printf '%d' ...) once per UTF-8 byte. Now bash/zsh use a fork-free printf -v path and other shells a generated case keyed on the chr table (extended to 255). Returns unsigned 1-255, which also makes event.sh's UTF-8 lead-byte checks reliable on signed-char platforms.
  • hid.sh: collapse up to 24 sequential modifier-helper calls per modified key into one head-case + one modifier-case (modifier slot anchored as exactly two digits, rejecting extra-parameter sequences). Resolve the most frequent class C (typing) first via early return. Remove the now unused _tuish_5code/6code_modifiers helpers.
  • str.sh: inline the UTF-8 decode in tuish_str_width over the local value, dropping the per-byte eval indirection; codepoint arithmetic unchanged.

Adds a headless cross-shell benchmark harness under tests/bench/ and a resolver-level golden test (tests/unit/test_event_modifiers.sh) covering the full key x modifier cross product; folds the direct-helper tests into it.

Pure-shell perf work focused on the keystroke→event→redraw path,
validated across bash/zsh/ksh93/mksh/busybox with byte-identical behavior.

- ord.sh: make _tuish_ord fork-free for bytes >=128. The old non-ASCII
  fallback forked $(printf '%d' ...) once per UTF-8 byte. Now bash/zsh use
  a fork-free `printf -v` path and other shells a generated case keyed on
  the chr table (extended to 255). Returns unsigned 1-255, which also makes
  event.sh's UTF-8 lead-byte checks reliable on signed-char platforms.
- hid.sh: collapse up to 24 sequential modifier-helper calls per modified
  key into one head-case + one modifier-case (modifier slot anchored as
  exactly two digits, rejecting extra-parameter sequences). Resolve the
  most frequent class C (typing) first via early return. Remove the now
  unused _tuish_5code/6code_modifiers helpers.
- str.sh: inline the UTF-8 decode in tuish_str_width over the local value,
  dropping the per-byte eval indirection; codepoint arithmetic unchanged.

Adds a headless cross-shell benchmark harness under tests/bench/ and a
resolver-level golden test (tests/unit/test_event_modifiers.sh) covering the
full key x modifier cross product; folds the direct-helper tests into it.
@alganet
alganet merged commit 93d9d39 into main Jun 13, 2026
10 checks passed
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.

1 participant