Skip to content

perf: reuse universal event dispatchers - #1008

Merged
domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/reuse-universal-event-dispatchers-981
Sep 9, 2026
Merged

domgan-oai merged 1 commit into
octanejs:mainfrom
openai-oss-forks:codex/reuse-universal-event-dispatchers-981

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Reuse the universal event dispatcher for a surviving ordinary-host listener ID across accepted commits.
  • Retire removed or hidden IDs after publishing the surviving handler records, and leave the collapsed-template event path intact.
  • Extend the universal event benchmark with ordinary hosts, plus public listener lifecycle regressions.

Why

Issue #981 records that every ordinary universal event update removes and re-inserts each listener in three collections and allocates a new dispatcher. The dispatcher already looks up the current handler by ID, so the existing closure can serve subsequent accepted updates.

Changes

  • Keep a surviving listener in the published dispatcher table while replacing its current handler; remove IDs absent from the accepted event sites.
  • Verify original IDs dispatch the latest callback, retired IDs cannot dispatch, and a surviving collapsed-template listener stays live through removal and restoration of its neighbor.
  • Add 128- and 1,024-listener ordinary-host targets with stable identity, latest callback, and zero redundant host-command controls.
  • Add an octane patch changeset.

Validation

  • pnpm sync and scoped pnpm format:files:check
  • pnpm typecheck
  • ./node_modules/.bin/vitest run packages/octane/tests/universal*.test.ts --reporter=dot (36 dev/prod files, 712 tests)
  • Both new stale-ID assertions fail under deliberate missing-retirement mutants and pass after restoration.
  • Interleaved B–C–C–B benchmark, 13 samples/process: regular 128 listeners 0.108/0.109 → 0.079/0.079 ms per update; regular 1,024 listeners 0.896/0.945 → 0.668/0.679 ms per update. Existing collapsed controls remained near baseline. An untimed dispatcher-registration probe counted 43,776 → 2,304 registrations over the same initial mount plus 36 updates.
  • pnpm test: local all-project run encountered unrelated browser sandbox failures; outside the sandbox a representative browser test passed, but the unrestricted all-project run also reported unrelated email-cli and Jotai failures before it was stopped. Current-head CI is the full repository gate.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches universal commit-time event listener lifecycle in core runtime code, though behavior is constrained by new tests and benchmark correctness gates.

Overview
Ordinary-host handler updates no longer tear down and recreate every EVENT_DISPATCHERS entry on each accepted commit. Surviving listener IDs keep their existing dispatcher while the handler table is updated; dispatchers and published IDs are only created when missing, and IDs are retired only after re-staged events are applied (still clearing collapsed-template listeners the same way as before).

Regression coverage adds tests that stable listener IDs reach the latest closure via root.dispatchEvent, removed sites throw for stale IDs, and collapsed-template neighbors stay correct through hide/restore. The universal-template-events benchmark now runs both collapsed-template and ordinary object-driver workloads at 128/1,024 sites, with extra guards (distinct listener IDs, zero redundant host commands, original ID → latest handler) and optional BENCH_RUNTIME_URL to skip rebuilds. An octane patch changeset documents the behavior change.

Reviewed by Cursor Bugbot for commit 35bb2db. Bugbot is set up for automated code reviews on this repo. Configure here.

@domgan-oai
domgan-oai marked this pull request as ready for review September 9, 2026 07:33
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 9, 2026
@domgan-oai
domgan-oai merged commit f86fb48 into octanejs:main Sep 9, 2026
47 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant