Skip to content

perf(tui): faster insert mode via persistent tmux control connection#2

Merged
Fabio-RibeiroB merged 2 commits intoFabio-RibeiroB:mainfrom
bradymd:perf/insert-mode-fast-keys
Mar 23, 2026
Merged

perf(tui): faster insert mode via persistent tmux control connection#2
Fabio-RibeiroB merged 2 commits intoFabio-RibeiroB:mainfrom
bradymd:perf/insert-mode-fast-keys

Conversation

@bradymd
Copy link
Copy Markdown

@bradymd bradymd commented Mar 23, 2026

Summary

  • Replace per-keystroke tmux send-keys subprocess with a single persistent tmux -C attach control mode process
  • Each keypress in insert mode is now a pipe write (~0.1ms) instead of a fork+exec (~5-10ms)
  • Minor: avoid redundant filteredSessions() call when entering insert mode with i

How it works

internal/tmux/control.go maintains a package-level tmux -C attach process. On first use it starts the process, drains its stdout (required so the pipe never blocks), and holds the stdin pipe open. SendKeyFast then just does fmt.Fprintf(stdin, "send-keys -t %s '%s'\n", ...) — no process spawn per key.

Falls back to the existing SendKeys subprocess path if the control session fails to start (e.g. no tmux server).

Test plan

  • Enter insert mode with i, type — characters should feel near-instant
  • Esc exits insert mode cleanly
  • Works across multiple sessions / switching selected session
  • Fallback: kill the control process externally, verify keys still send

🤖 Generated with Claude Code

Mark Brady and others added 2 commits March 23, 2026 19:44
Replace per-keystroke subprocess spawning with a single long-lived
`tmux -C attach` process. Each key in insert mode is now a plain pipe
write (~0.1ms) rather than a fork+exec of tmux send-keys (~5-10ms).

Also avoids a redundant filteredSessions() call when entering insert mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Fabio-RibeiroB Fabio-RibeiroB force-pushed the perf/insert-mode-fast-keys branch from ec5edc3 to 689e413 Compare March 23, 2026 19:48
@Fabio-RibeiroB Fabio-RibeiroB merged commit 5421c8d into Fabio-RibeiroB:main Mar 23, 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