Skip to content

refactor(input, composer): apply the go fix modernizers - #1538

Merged
Gaurav-Gosain merged 2 commits into
mainfrom
refactor/input-composer-modern-loops
Nov 4, 2026
Merged

Gaurav-Gosain merged 2 commits into
mainfrom
refactor/input-composer-modern-loops

Conversation

@Gaurav-Gosain

Copy link
Copy Markdown
Owner

Two go fix modernizers in internal/input and internal/composer, one commit per package. Behaviour stays the same and the binary does not grow.

Scope

  • input: isConfiguredKey tests the composed chords with slices.ContainsFunc. It still stops at the first chord that matches.
  • composer: historyMatches walks m.hist newest first with slices.Backward. The body only reads the slice.

Left out on purpose

  • go fix also rewrites two loops in input/copymode_visual.go with slices.Backward. With that form lastPrintedCell no longer inlines, and the text section grows by 283 bytes. Copy mode reads no faster for it, so I kept the index loops.
  • go fix rewrites the window loop in learn/commands.go (reset) too. That body calls DeleteWindow, which shrinks the slice it walks, so I did not touch it.

Verification

  • just check --changed passes. Its fix report lists the two copy-mode loops above.
  • go test passes for internal/input and internal/composer.
  • Binary size with the release flags, against main at 57150e1: linux/amd64 46,919,840 bytes before and after, darwin/arm64 43,707,106 before and after. In the linux text section isConfiguredKey grows by 26 bytes and historyMatches shrinks by 22.
  • Key routing benchmarks, -count 10, before and after on the same machine. I ran them on the first version of this branch, which also had the copy-mode loops. Key routing does not reach those loops. Allocations are the same in every one. Time is within noise except KeyPrefixChord, which went from 2.446 to 2.393 µs (p=0.000).
Benchmark ns/op before ns/op after allocs/op
KeyTerminalTyped 1,782 1,767 21
KeyTerminalCtrl 2,353 2,357 35
KeyPrefixChord 2,446 2,393 27
MouseSweepContent 8,361 8,378 17

The composer benchmarks (Keystroke16KiB, FrameUnchanged) also hold their allocations, 292 and 0.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Binary size

target this change main change room under the ceiling
darwin/arm64 43724354 bytes 43724354 bytes +0 bytes (+0.0 KiB) 3275646 bytes
linux/amd64 46944416 bytes 46944416 bytes +0 bytes (+0.0 KiB) 55584 bytes

The ceiling is 47000000 bytes for each target. Main's size is from main at c606b6b (https://github.com/Gaurav-Gosain/tuios/actions/runs/41818148802).

State the size cost in the pull request body. CI fails only above the ceiling.

historyMatches only reads m.hist, so the order and the indexes it returns
stay the same.
go fix suggested it. isConfiguredKey returns the same answer and still
stops at the first chord that matches.

go fix also rewrote two copy-mode loops in copymode_visual.go with
slices.Backward. I left them out: lastPrintedCell then grows past the
inlining budget and the text grows by 283 bytes.
@Gaurav-Gosain
Gaurav-Gosain force-pushed the refactor/input-composer-modern-loops branch from d967294 to 50bb2d7 Compare November 4, 2026 11:02
@Gaurav-Gosain
Gaurav-Gosain merged commit 50bb2d7 into main Nov 4, 2026
35 checks passed
@Gaurav-Gosain
Gaurav-Gosain deleted the refactor/input-composer-modern-loops branch November 4, 2026 11:21
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