Repository navigation
perf(pi): skip rewriting current managed extensions on every terminal spawn - #38481
Merged
Merged
Conversation
… spawn Each local terminal spawn with a Pi agent home rewrote three Orca-owned extension files (~54 KB) synchronously on the main thread even when their contents were already current. Compare the read we already do for the ownership check and write only when the content differs.
OrcaWin
marked this pull request as ready for review
November 5, 2026 09:09
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 2 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PiTitlebarExtensionService.buildPtyEnvruns on the main thread for every local terminal spawn when agent status hooks are on and a Pi agent home exists (~/.pi/agent, or a configured one). This includes bare shells. Each call ranwriteFileSyncon three Orca-owned extension files (orca-titlebar-spinner.ts,orca-prefill.ts,orca-agent-status.ts, about 54 KB together) in the user'sextensions/dir, even when they already held the current source.The ownership check already read each file (
canOverwriteManagedExtension) and then threw away what it read. So restoring 50 tabs did 150 synchronous file writes in the user's home, and every new tab rewrote the files and bumped their mtimes. In a main-process CPU profile of one launch,installManagedExtensionstook about 36 ms, about 22 ms of it inwriteFileUtf8.The OpenCode and OMP equivalents (
writeOpenCodePluginConfig,materializeOmpFreshConfig) already compare before writing. Pi was the outlier.Fix
writeManagedExtensionreads the file once:skipped-user-owned(as before)The redundant
existsSyncandcanOverwriteManagedExtensionare removed. Net: one method, same outcomes.Measurements
Environment: M4 Air, macOS 26, Node 26 through vitest. A temporary harness (not committed) calls
buildPtyEnv('pty-i', home, 'pi')N times on a tmp Pi home after one warm-up spawn and countswriteFileSynccalls through anode:fsmock. There were 3 runs each at base and fix.writeFileSynccalls, 50 spawnswriteFileSynccalls, 500 spawnsThe timings are on a warm tmpdir. Writes into a real home dir (Spotlight/FSEvents) cost more, as the in-app profile above shows. The write and byte counts are deterministic.
The new unit test ("leaves current Orca-owned extensions untouched on later spawns") sets the installed files' mtime to 0, spawns again and asserts the mtime is still 0. It fails without the fix.
Risk / compat
Test plan
pnpm test src/main/pi/titlebar-extension-service.test.ts src/main/pi/titlebar-extension-overlay-path.test.tspnpm tc:node, oxlint, oxfmt