Skip to content

perf(runner): run inline when no random delay is configured#565

Merged
merencia merged 1 commit into
mainfrom
perf/inline-zero-jitter-run
Jun 21, 2026
Merged

perf(runner): run inline when no random delay is configured#565
merencia merged 1 commit into
mainfrom
perf/inline-zero-jitter-run

Conversation

@merencia

Copy link
Copy Markdown
Member

What

Run the task inline on the heartbeat tick when no random delay is configured, instead of always wrapping it in setTimeout(fn, randomDelay).

Why

The per-fire setTimeout exists to apply a random jitter, but the default maxRandomDelay is 0, so the delay is always 0 and the timer only adds a macrotask hop (and ~1ms+ of avoidable firing drift) with no effect. The timer is kept when a positive delay is configured. The next heartbeat is armed before the execution runs, so scheduling timing is unaffected.

Impact

  • Per-tick firing bias dropped from ~3ms to ~1.6ms in local testing.

Notes

  • Behaviour unchanged; all 374 tests pass.

Every fire was wrapped in setTimeout(fn, randomDelay) to apply jitter, but with
the default maxRandomDelay of 0 the delay is always 0, so the timer only added a
macrotask hop (and ~1ms+ of avoidable firing drift) with no effect. Run the task
inline on the heartbeat's own tick when no jitter is configured, and keep the
timer only when a positive delay is set. The next heartbeat is armed before the
execution runs, so timing is unaffected.
@merencia
merencia merged commit dad56e1 into main Jun 21, 2026
5 of 6 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.

1 participant