# perf\(web,desktop\): stop re-doing work on every render and unblock the login-shell probe · PR \#23857 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/23857)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: open

Source repository: Unavailable fork

Source branch: perf/render-and-probe-fixes

Target branch: main

Head commit: 8f94364bd90a264a9adb42ca2d1f1166e55da480

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/23857)

[Commits](https://git.cafe/pingdotgg/t3code/pull/23857/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/23857/diffs?format=markdown)

## Description

---

Several render-path and startup hot spots re-did work every time: streaming markdown threw away its parse cache, the diff panel re-parsed its patch, `useLocalStorage` rebuilt its codec, and the desktop login-shell probe could hang on stderr. Each is fixed minimally, and the terminal link scan gets a regression bench.

| Fix | Metric | Before | After | Change |
|---|---|---|---|---|
| **TERM-1** link regex (10k dense chars) | Scan time | 159.3 ms | 0.075 ms | ~2,100× faster |
| TERM-1 (2k dense chars) | Scan time | 6.39 ms | 0.015 ms | ~430× faster |
| TERM-1 (10k spaced chars) | Scan time | 0.081 ms | 0.063 ms | no real change |
| **MD-1** markdown plugin (3-render stream, 200-line fence) | Characters parsed | 10,278 | 3,456 | 66% fewer |
| **DIFF-1/2** diff panel (77 kB, 20-file patch) | Parse time per render | ~1.04 ms (min), 1.21 ms (median) | cache lookup, effectively free | ~1 ms saved per render |
| **WEB-1** `useLocalStorage` | Decode time | 4.87 µs | 1.68 µs | ~2.9× faster |
| **SH-3** login-shell probe (256 KB stderr) | Child exit | still running at 3 s kill | 17 ms | no longer hangs |

Notes:
- **TERM-1:** HEAD already contains the fix (lookbehind from #20264). The "before" is the old regex timed in a standalone script. This PR only adds `links.bench.ts` as a guard.
- **MD-1:** `createIncrementalMarkdownPlugin` is now created once per component (`useState`), so its prefix cache survives re-renders. Gain is measured in characters parsed, not time.
- **DIFF-1/2:** `getRenderablePatch` results are cached at module level, keyed by theme, `compactPartialHunkOffsets` and `ignoreWhitespace`, and compared by patch string. Bounded at 8 entries. Stable output also lets the existing `fileEntryCache` hit. The saving is small because `parsePatchFiles` already has an internal cache.
- **WEB-1:** `Schema.fromJsonString(schema)` is cached per schema in a `WeakMap`.
- **SH-3:** the login-shell probe piped stderr but never read it, so a shell rc writing more than the pipe buffer stalled until the 5 s timeout and PATH was never hydrated. stderr is now ignored.

Not covered: the benches were not run (`vp test bench` does not launch here), typecheck was not run by the reviewer, and the diff-panel change has no automated test. Measurements were taken locally by the implementing agent and independently spot-checked for TERM-1 by a second agent.

Tests run: 15 web test files (146 tests) and `DesktopShellEnvironment.test.ts` (13 tests) pass; lint is clean on touched files.

Implemented by Claude Sonnet 5.5 (medium) and reviewed by a second Sonnet 5.5 (medium) agent, via Claude Code in T3 Code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

