Skip to content

perf(events): avoid arguments/forEach allocation in event buses#4905

Draft
lukecotter wants to merge 1 commit into
tabulator-tables:masterfrom
lukecotter:perf/event-bus
Draft

perf(events): avoid arguments/forEach allocation in event buses#4905
lukecotter wants to merge 1 commit into
tabulator-tables:masterfrom
lukecotter:perf/event-bus

Conversation

@lukecotter

Copy link
Copy Markdown
Contributor

Summary

Reduce per-call allocation in the internal and external event buses. Behaviour-preserving.

Changes

  • _dispatch/_debugDispatch in both buses use rest params + indexed loops instead of Array.from(arguments) + forEach closures.
  • _chain reuses a single args array across subscribers (mutating only the trailing accumulator slot) rather than allocating a fresh concat per subscriber. Stock semantics are preserved: an array return value is passed to the next subscriber as a single argument, and a key with no (or emptied) subscribers returns the fallback.

Benchmarks (Node, 250k calls, 5 subscribers)

  • internal _dispatch: +87% (7.4×)
  • external _dispatch: +89% (8.9×)
  • internal _chain: +84% (6.3×)

Tests

Adds InternalEventBus._chain unit tests (accumulator threading, single-argument value passing, empty-subscriber fallback). Full suite green.

Internal and External event bus _dispatch/_chain use rest params and indexed loops instead of Array.from(arguments) plus forEach closures. _chain reuses a single args array across subscribers and preserves stock semantics (an array return is passed as one argument; an empty subscriber list returns the fallback). Adds InternalEventBus._chain unit tests.
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