Skip to content

perf(background): prevent overlapping refresh ticks - #607

Closed
JustYannicc wants to merge 121 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-background-refresh-inflight-20260705
Closed

perf(background): prevent overlapping refresh ticks#607
JustYannicc wants to merge 121 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-background-refresh-inflight-20260705

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Added a shared per-timer in-flight guard for background refresh ticks.
  • Wrapped extension and inline-script interval callbacks so a timer skips ticks while its previous async refresh is still running.
  • Added regression coverage for overlapping extension refresh, overlapping inline script refresh, and independent timers running concurrently.

Why

Slow runExtension, hidden no-view enqueueing, runScriptCommand, or fetchCommands work could outlive the configured interval. The previous setInterval(async () => ...) path allowed repeated overlapping starts for the same background command, creating avoidable IPC/script/build pressure over long sessions.

Compatibility impact

  • Manual launches are unaffected because only background interval callbacks use the new guard.
  • Independent background commands still run independently because each timer gets its own guard closure.
  • Menu-bar active checks remain inside the extension background tick before dispatching sc-launch-extension-bundle, preserving the existing Raycast-compatible menu-bar behavior.

How tested

  • node --test scripts/test-background-refresh-inflight.mjs
  • node --test scripts/test-background-refresh-timer-diff.mjs scripts/test-background-no-view-dedupe.mjs
  • node /opt/homebrew/lib/node_modules/npm/bin/npm-cli.js run typecheck:renderer
  • node /opt/homebrew/lib/node_modules/npm/bin/npm-cli.js run build:renderer
  • Codex LSP diagnostics on src/renderer/src/hooks/backgroundRefreshTimers.ts and src/renderer/src/hooks/useBackgroundRefresh.ts: no errors.

Performance evidence

Focused slow-work timer harness, intervalMs=10, workMs=35, durationMs=130:

  • Before edits: totalStarts=10, completed=10, maxConcurrent=4.
  • After edits through the production guard: totalStarts=3, completed=3, maxConcurrent=1.

Stack validation

Started from codex/perf-wave4-integrated-stack-20260705 at ac90ce403aeddab98d0a1b245afce268c48b8bfd, verified with git rev-parse HEAD before editing. Implementation branch: codex/perf-background-refresh-inflight-20260705.

Replaces

None.

(cherry picked from commit 83c2a89)
(cherry picked from commit 0a7560b)
# Conflicts:
#	src/renderer/src/raycast-api/hooks/use-cached-promise.ts
…launcher surfaces

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime-renderers.tsx
#	src/renderer/src/raycast-api/list-runtime.tsx
…IO stalls

# Conflicts:
#	src/renderer/src/CameraExtension.tsx
# Conflicts:
#	src/renderer/src/raycast-api/list-runtime.tsx
…resh overhead

# Conflicts:
#	scripts/bench-script-command-discovery.mjs
#	scripts/benchmark-file-search-delete-batch.mjs
#	scripts/lib/script-command-runner-harness.mjs
#	scripts/lib/ts-import.mjs
#	scripts/test-file-search-delete-batch.mjs
#	scripts/test-script-command-runner.mjs
#	src/main/file-search-index.ts
#	src/main/main.ts
…hurn

# Conflicts:
#	scripts/lib/script-command-runner-harness.mjs
#	scripts/lib/ts-import.mjs
#	scripts/test-extension-lifecycle-sandbox.mjs
#	scripts/test-script-command-runner.mjs
#	src/main/main.ts
#	src/renderer/src/ExtensionView.tsx
… hot paths

# Conflicts:
#	scripts/test-use-frecency-sorting.mjs
#	src/renderer/src/raycast-api/form-runtime.tsx
#	src/renderer/src/raycast-api/grid-runtime-hooks.ts
#	src/renderer/src/raycast-api/grid-runtime-items.tsx
#	src/renderer/src/raycast-api/hooks/use-frecency-sorting.ts
# Conflicts:
#	.github/workflows/project-checks.yml
#	package.json
#	scripts/file-search-perf-harness.mjs
#	scripts/test-browser-search-performance.mjs
#	scripts/test-file-search-perf-harness.mjs
#	scripts/test-root-search-perf.mjs
#	src/renderer/src/CameraExtension.tsx
#	src/renderer/src/hooks/useBrowserSearch.ts
#	src/renderer/src/raycast-api/list-runtime.tsx
…cle and media fixes

# Conflicts:
#	scripts/lib/ts-import.mjs
#	scripts/measure-extension-bundle-cache.mjs
#	src/main/commands.ts
#	src/main/extension-runner.ts
#	src/main/main.ts
#	src/renderer/src/ExtensionView.tsx
#	src/renderer/src/raycast-api/grid-runtime-hooks.ts
#	src/renderer/src/raycast-api/list-runtime-hooks.ts
@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by the consolidated runtime/lifecycle/media PR: #622

@JustYannicc JustYannicc closed this Jul 5, 2026
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.

1 participant