Skip to content

perf(runtime): reduce extension and menubar churn - #530

Merged
shobhit99 merged 2 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/consolidate-runtime-background-menubar
Jul 11, 2026
Merged

shobhit99 merged 2 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/consolidate-runtime-background-menubar

Conversation

@JustYannicc

@JustYannicc JustYannicc commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

  • Consolidates runtime, background refresh, menu-bar, cache, OAuth, exec, and hook lifecycle performance fixes into one upstream PR.
  • Adds bounded/incremental caches for withCache, Raycast Cache, extension wrapper compilation, extension bundle preparation, and menu-bar visible payload updates.
  • Reduces long-running menu-bar churn by avoiding storage self-remounts, deduping background no-view runs, and retaining unchanged background refresh timers.
  • Reduces extension runtime overhead by preferring in-process Node facades for sync fs/child_process paths and by clearing abortable promise and exec timeout handles.
  • Caps unmatched OAuth callback retention and coalesces inline command argument settings writes.
  • Adds focused regression and measurement scripts for the touched runtime paths.

Why

Long-lived menu-bar sessions can accumulate work from repeated refresh timer recreation, unchanged tray payload IPC, storage-triggered remounts, background no-view overlap, cache growth, sync IPC, and callback queues. This PR combines the related fixes so the upstream review can evaluate the full lag-reduction path together.

Compatibility impact

  • Raycast-compatible behavior is preserved: external and sibling storage changes still refresh menu-bar commands, while a menu-bar command no longer remounts itself for its own local storage write.
  • User-initiated no-view launches are still allowed to overlap; only background ticks for the same extension command are deduped while a run is in flight.
  • Extension wrapper and bundle caches invalidate on code or file-stat changes, and install/uninstall/build paths clear runner caches.
  • Legacy Raycast cache metadata is migrated or repaired, and per-key has/remove still reconcile stale localStorage entries.
  • OAuth callback semantics remain state-based, with stale/unmatched callbacks pruned to avoid unbounded queue growth.

How tested

  • node --test scripts/test-with-cache-expiry.mjs scripts/test-menubar-payload-cache.mjs scripts/test-extension-wrapper-cache.mjs scripts/test-extension-bundle-cache.mjs scripts/test-menubar-storage-remounts.mjs scripts/test-abortable-promise-hooks.mjs scripts/test-inline-args-write-coalesce.mjs scripts/test-extension-sync-facade.mjs scripts/test-raycast-cache-size-index.mjs scripts/test-background-no-view-dedupe.mjs scripts/test-background-refresh-timer-diff.mjs scripts/test-exec-command-timeout-cleanup.mjs scripts/test-oauth-callback-queue.mjs
  • node scripts/measure-extension-wrapper-cache.mjs
  • node scripts/measure-extension-bundle-cache.mjs
  • pnpm exec tsc -p tsconfig.main.json --noEmit --pretty false
  • pnpm test
  • pnpm exec tsc -p tsconfig.renderer.json --noEmit --pretty false fails on the standalone branch because of existing repo-wide renderer typing debt unrelated to this consolidation.

Performance evidence

  • Menu-bar equivalent visible payload registrations drop from 3 sends to 1 send.
  • Background refresh unchanged updates drop from legacy created=2 cleared=2 to keyed created=0 retained=2 cleared=0.
  • Background no-view duplicate ticks drop from queued=3 to queued=1 skipped=2.
  • Extension wrapper compilation drops from 1000 wrapper creations to 1 cached wrapper creation in the focused harness.
  • Raycast cache benchmark avoids full scans on set/eviction (set-fill getItem=0, set-with-eviction getItem=0).
  • Extension sync facade Node path reports 0 sync IPC calls for real path ops in the focused harness.

Stack validation

Applied this consolidation over codex/consolidate-validation-checks (fix(validation): restore project checks) and validated the combined stack:

  • pnpm exec tsc -p tsconfig.renderer.json --noEmit --pretty false
  • pnpm test

Replaces

This was referenced Jul 3, 2026
@shobhit99

Copy link
Copy Markdown
Contributor

This PR consolidates 13 upstream perf PRs: bounded/incremental caches (Raycast Cache size index, extension manifest/bundle/wrapper caches, withCache eviction), key-stable background-refresh timers, menu-bar payload dedup + self-remount suppression, background no-view dedup, abortable-promise/exec-timeout cleanup, an OAuth callback queue bound, in-process Node fs/child_process sync facades, and debounced command-argument settings sync, plus ~3k lines of focused node --test scripts.

Reviewed the full diff across all 20 source files. Overall this is careful, well-tested work that is behavior-preserving in most areas. One change stands out as a genuine behavior shift worth verifying before merge.

Strengths

  • exec-command extraction (src/main/exec-command.ts) is a faithful move of the inline run-command IPC handler, and it fixes a latent issue by clearing the 5-min timeout on completion (base left it armed, so it would proc.kill() a dead process later).
  • extension-runner stat-signature caches invalidate correctly: build/single-build paths call invalidateExtensionStaticCacheForPath, and install/uninstall/build in extension-registry.ts call the full invalidateExtensionRunnerCaches(). Verified no caller mutates the now-shared cached pkg object, so the shared-reference manifest cache is safe.
  • usePromise / useCachedPromise now abort superseded runs and guard stale state writes via isCurrentRun() — this is more correct than base (which orphaned in-flight runs and could let an old resolution overwrite new data), not merely faster. Abort-on-unmount is guarded so the resulting AbortError doesn't surface.
  • OAuth callback queue (oauth-bridge.ts): parse-once + "handled by waiter" dedup + prune/cap fixes a real base bug where consumed URLs were left in the queue and the queue could grow unbounded.
  • Raycast Cache: O(1) size tracking via incremental sizeByKey/totalSize, with a proper v1→v2 metadata migration and reconciliation when localStorage is mutated externally. Nicely done.
  • No i18n impact — no user-facing strings were added/renamed/removed (only console.* logs).

Concerns / potential bugs

  1. (Primary — please verify before merge) fs / child_process now resolve to the SuperCmd stub facade even in Node-enabled extension hosts. In ExtensionView.tsx, loadExtensionExport's fakeRequire gained a shouldUseSuperCmdBuiltinFacade(name) early-return that hands back fsStub / childProcessStub for fs, fs/promises, and child_process before tryRealNodeRequire(name). Base returned the real Node modules first, and real Node require is available here (confirmed via _realNodeRequire / window.__scNodeRequire). fsStub/childProcessStub are plain object literals with no fallthrough to the real module, so anything they don't implement is absent or a no-op stub: createReadStream/createWriteStream are stubs (not real disk streams), and watch, cpSync, mkdtempSync, appendFileSync, readlinkSync/symlinkSync, opendir, chmodSync, the Dirent/Stats classes, and real streaming async child_process.spawn/exec are missing. Extensions relying on real streaming fs or real child processes in a Node-enabled window could regress. The common sync read/stat/readdir/exists paths do delegate to real fs (via getRealNodeFsModule()), so this is likely intentional (asset-path layering + sync-IPC reduction) and fine for the majority — but I'd (a) confirm this matches the intended node-integration model, and (b) consider making the facades fall through to the real module for members they don't implement (e.g. a Proxy backed by the real module, or spreading it).

  2. (Low) Leftover per-load debug log. getCompiledExtensionWrapper's call site logs console.debug('[loadExtensionExport] Wrapper cache hit/miss …') on every extension load. Drop it or gate it behind a debug flag.

  3. (Low) Menu-bar remount throttle reorder (useMenuBarExtensions.ts, remountMenuBarExtensionsForExtension). The 200ms throttle timestamp is now written inside the setState updater and only if (changed). Two sc-extension-storage-changed events firing synchronously in the same tick (before React flushes the updater) can both pass the now - lastTs < 200 guard and both remount, where base recorded the timestamp synchronously and would throttle the second. Net effect is an occasional extra remount (mildly ironic for a churn-reduction PR) — not incorrect. Also, mutating a ref inside the updater is a side-effect-in-reducer pattern (double-invoked under StrictMode, though idempotent here).

  4. (Low, theoretical) Wrapper cache key collisions. extension-wrapper-cache.ts keys on extensionIdentity + code.length + 32-bit FNV-1a(code). A same-identity, same-length, same-hash collision would return a stale wrapper. Astronomically unlikely per-extension; noting for completeness.

  5. (Low) Cache.has() gained side effects. On the size-mismatch reconciliation path it calls updateLRU + saveToStorage, so has() can bump LRU recency (Raycast's has is conceptually a pure existence check). Only triggers on external localStorage mutation, so minor.

Suggestions

  • Confirm CI actually executes the new scripts/test-*.mjs (node --test) suite — otherwise the strongest safety net for this consolidation isn't running in the pipeline.
  • This is a large, cross-subsystem PR (41 files, +5k/-377) folding 13 PRs together. ~3k lines are tests (good), but a regression in the source will be hard to bisect/revert granularly; concern feature request: can we use flat subscription to use ai features using claude sdk and codex sdks ? #1 in particular would be easier to reason about as its own commit.

🟡 Approve with minor comments — the work is careful and well-tested; concern #1 (fs/child_process facade preference) is the one behavior change I'd want confirmed against real extensions before merging.

🤖 Automated review by Claude Code (Opus 4.8).

@JustYannicc

JustYannicc commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

Addressed the actionable review feedback in 11b7b72:

  • fs / child_process facade priority/fallthrough: kept the SuperCmd overlay for virtual/localStorage-aware behavior, but fakeRequire now returns a proxy-backed facade in Node-enabled hosts so missing members fall through to real Node modules. Placeholder fs methods that previously blocked real Node (openSync, readSync, writeSync, closeSync, rmdirSync, stream/watch helpers, etc.) now delegate to real fs when available, and child_process.fork delegates to real Node when available.
  • Wrapper-cache debug logging: gated the per-load [loadExtensionExport] Wrapper cache ... log behind globalThis.__SUPERCMD_DEBUG_EXTENSION_WRAPPER_CACHE so normal extension loads stay quiet.
  • Menu-bar remount throttle: timestamping is synchronous before queued React state updates, but only after confirming there is a real remount target. Added a regression test for a self-originated no-op write followed immediately by an external refresh.
  • Test-suite execution: added .github/workflows/test.yml so PRs/pushes touching root source/scripts/package metadata run npm ci + npm test.

Verification:

  • node --test scripts/test-background-no-view-dedupe.mjs scripts/test-background-refresh-timer-diff.mjs scripts/test-extension-sync-facade.mjs scripts/test-menubar-storage-remounts.mjs scripts/test-oauth-callback-queue.mjs ✅ 24 passed
  • git diff --check ✅

@shobhit99
shobhit99 self-requested a review July 11, 2026 01:21
@shobhit99
shobhit99 merged commit 2da7b9e into SuperCmdLabs:main Jul 11, 2026
1 of 3 checks passed
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