Repository navigation
let a host count batches and continuations - #50
Merged
Merged
Conversation
Work run during a drain can call `schedule`, which appends to the table the drain is walking. Generalised iteration is not guaranteed to reach entries added after it started, so an effect scheduled by another effect could be skipped for the rest of the batch and then discarded by the `table.clear` that ends it. Both drains now index by position, which re-reads the length each time round. Co-authored-by: Cursor <cursoragent@cursor.com>
A runtime that drives signals wants to know how much work each batch turned into, and it cannot see that from outside. `setHooks` takes the counters it cares about, so nothing here needs to know about the profiler reading them. They are bound as upvalues rather than read out of a table per batch, so a hook that is not installed costs what a constant did. `runWork` no longer calls the batch function itself, which lets the continuation count be taken once the batch has finished scheduling and before the drain starts. Co-authored-by: Cursor <cursoragent@cursor.com>
hcollinsblox
requested review from
Gravemind1142
and removed request for
a team
September 22, 2026 17:15
MisterUncloaked
requested changes
Oct 6, 2026
MisterUncloaked
left a comment
There was a problem hiding this comment.
Drafted by my agent and reviewed by me.
Missing tests plus a few should-fix items inline.
…cheduler-profiling-hooks
MisterUncloaked
requested changes
Oct 20, 2026
hcollinsblox
requested review from
MisterUncloaked
and removed request for
Gravemind1142
October 21, 2026 16:04
MisterUncloaked
approved these changes
Oct 21, 2026
MisterUncloaked
left a comment
There was a problem hiding this comment.
Drafted by my agent and reviewed by me.
LGTM, thanks. The hooks-off path now matches main. Two non-blocking notes: the description still says the count is taken before the drain, and doesn't mention that empty batches are no longer reported. Also, calling onBatch next to onContinuations after the drain, under the one hooksInstalled and #continuations > 0 guard, would drop the flag-off path that clears queued work when onBatch throws. Fine as a follow-up.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SignalsScheduler.setHooks takes onBatch and onContinuations. Unset hooks are noops bound as upvalues, so an uninstalled hook costs what a constant did. runWork no longer calls the batch function itself, so the continuation count is taken after the batch has finished scheduling and before the drain starts.
Why this is useful on its own
A runtime that drives this scheduler wants to know how much work each batch turned into, and it cannot see that from outside. Putting a profiler inside the scheduler would couple the two. Host-supplied hooks keep the package ignorant of whoever is counting. The drain-by-index fix is the base because the count has to include work scheduled during the drain.
Use in Blox
Installed at module load when Debug.PROFILE is on:
That is how the Blox profiler attributes “this frame spent N batches / M continuations”. Without the hooks, profiling the scheduler means forking it.