Reduce terminal input latency via portal hosting + selected-only workspace mounting

Merged
LA
9mo ago
+1799-183

Summary

  • Portal-host terminal views into a shallow window-level host (WindowTerminalPortal) instead of keeping each terminal deep in the SwiftUI container tree.
  • Route overlay hit-testing through the portal host so file-drop/mouse targeting still resolves the correct GhosttyNSView.
  • Mount only the selected workspace view in ContentView (mount policy default = 1) to reduce CA transaction traversal depth.
  • Add WorkspaceMountPolicyTests regression coverage.
  • Expose portal metadata in surface_health (portal, view_depth) and add tests/test_terminal_portal_hosting.py regression.
  • Improve simulate_shortcut to send keyDown + keyUp and use request-arrival timestamp for more representative latency instrumentation.
  • Add debug-only key latency probe logs (key.latency) gated by env/defaults for repeatable perf measurements.

Validation

  • CMUX_SOCKET=/tmp/cmux-debug-latency-host-oskey.sock python3 tests/test_terminal_portal_hosting.py ✅
  • xcodebuild -project GhosttyTabs.xcodeproj -scheme cmux-unit -configuration Debug -destination 'platform=macOS' -only-testing:GhosttyTabsTests/WorkspaceMountPolicyTests test ✅

Host Latency Measurements (OS keystrokes)

Tagged build: latency-host-oskey

Heavy load setup before typing:

  • 20 workspaces
  • ~6 splits per workspace

Loaded run (200 OS keystrokes):

  • appMonitor: n=167, p50=14.95ms, p95=26.24ms, p99=27.44ms, max=29.06ms
  • keyDown: n=167, p50=15.27ms, p95=26.56ms, p99=27.75ms, max=29.36ms

Light-load baseline run (150 OS keystrokes):

  • appMonitor: n=165, p50=8.25ms, p95=17.41ms, p99=22.18ms, max=27.01ms
  • keyDown: n=166, p50=8.58ms, p95=17.73ms, p99=22.51ms, max=27.31ms