Skip to content

perf(extensions): prune fired one-shot timers#565

Closed
JustYannicc wants to merge 71 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-extension-one-shot-timer-cleanup
Closed

perf(extensions): prune fired one-shot timers#565
JustYannicc wants to merge 71 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-extension-one-shot-timer-cleanup

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

Wrapped extension-scoped one-shot setTimeout and requestAnimationFrame callbacks so fired handles remove themselves from the lifecycle registry and clearer maps. Extended the lifecycle sandbox harness with a flushable fake clock, explicit clear/cancel coverage, thrown-callback coverage, unmount cleanup coverage, and interval-retention assertions.

Why

Long-lived menu-bar extensions can schedule repeated one-shot timers over hours. Those fired handles no longer need lifecycle cleanup, but they previously stayed in registry.timeouts and registry.rafs, growing memory and future cleanup work until unmount or re-evaluation.

Compatibility impact

No extension API shape changes. Timeout callback arguments and practical browser this binding are preserved through the wrapper, explicit clearTimeout and cancelAnimationFrame still untrack and cancel pending handles, setImmediate continues to delegate through timeout cleanup, and unmount cleanup still clears pending one-shots. Interval behavior remains explicit-clear/unmount based and intervals stay tracked until cleared.

How tested

  • node --test scripts/test-extension-lifecycle-sandbox.mjs -> 8/8 passing
  • node --test 'scripts/test-*.mjs' -> 242/242 passing
  • Codex LSP diagnostics with severity: error on src/renderer/src/ExtensionView.tsx -> no diagnostics

Performance evidence

  • 1000 fired timeouts: before stale registry entries=1000, after=0
  • 1000 fired RAFs: before stale registry entries=1000, after=0
  • The same harness confirms intervals remain tracked after one-shot timeout/RAF callbacks fire, then drop to zero after explicit clear.

Stack validation

Implementation branch was created from fork/codex/perf-consolidated-integration-stack after verifying both HEAD and that stack branch resolved to integration base 264fb89dc5c867d6c3d77bc4b95e26e235e326ea.

Replaces

None

…ated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/hooks/use-cached-promise.ts
…ated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime-renderers.tsx
#	src/renderer/src/raycast-api/list-runtime.tsx
…ated-integration-stack

# Conflicts:
#	src/renderer/src/CameraExtension.tsx
…ated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime.tsx
… into codex/perf-consolidated-integration-stack
@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated lifecycle/media wave-2 PR: #575

@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #575.

@JustYannicc JustYannicc closed this Jul 4, 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