Skip to content

Commit b268bed

Browse files
author
brettheap
committed
docs: add openspec proposal for TUI threaded rendering fix
1 parent d587f9c commit b268bed

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Change: Enable Threaded Rendering to Fix TUI Freezing
2+
3+
## Why
4+
5+
The TUI freezes for 6+ seconds during normal typing, making the application unusable during these periods. Users experience complete input lag where keystrokes are not registered until the freeze ends.
6+
7+
**Root Cause**: The @opentui native library makes FFI (Foreign Function Interface) calls to render the terminal UI. In Bun, FFI calls are synchronous and block the JavaScript event loop. The native rendering operations were taking ~6.5 seconds and occurring every ~5 seconds, causing periodic complete freezes.
8+
9+
**Diagnosis Method**: Created a heartbeat-based diagnostic that detected event loop blocks by measuring gaps between expected 100ms intervals. The diagnostic confirmed consistent ~6.5 second blocks.
10+
11+
## What Changes
12+
13+
- Enable `useThread: true` in the @opentui render configuration
14+
- This moves native FFI rendering calls to a separate thread, preventing them from blocking the JS event loop
15+
16+
**Code Change** (1 line):
17+
```typescript
18+
// packages/opencode/src/cli/cmd/tui/app.tsx
19+
render(component, {
20+
targetFps: 60,
21+
gatherStats: false,
22+
exitOnCtrlC: false,
23+
useThread: true, // Enable threaded rendering to avoid blocking the JS event loop
24+
useKittyKeyboard: {},
25+
// ...
26+
})
27+
```
28+
29+
## Impact
30+
31+
- **Affected specs**: None (bug fix restoring expected behavior - TUI should not freeze)
32+
- **Affected code**: `packages/opencode/src/cli/cmd/tui/app.tsx:152`
33+
- **Risk**: Low - the `useThread` option is a supported @opentui feature
34+
- **Testing**: Verified with perf diagnostics showing zero `[BLOCKED]` messages after fix
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Tasks: Enable Threaded Rendering
2+
3+
## 1. Implementation
4+
- [x] 1.1 Add `useThread: true` to render config in `app.tsx`
5+
6+
## 2. Verification
7+
- [x] 2.1 Run typecheck to ensure no type errors
8+
- [x] 2.2 Test TUI with normal typing - confirm no freezing
9+
- [x] 2.3 Verify with perf diagnostics (OPENCODE_PERF_DEBUG=1) - confirm zero blocked events
10+
11+
## 3. Cleanup
12+
- [x] 3.1 Remove diagnostic instrumentation code
13+
- [x] 3.2 Commit and push changes

0 commit comments

Comments
 (0)