Skip to content

Conversation

@boneskull
Copy link
Contributor

Fixes #139

This change enables Task to be aborted via an AbortSignal which falls back to a signal its
Bench's signal.

It adds a signal prop to the Task class, as well as an isAborted() method (which could be a
getter, if you wish).

I'm wrapping tinybench and have confirmed this works well, as I'm able to abort (async) tasks via
the signal.

I've added tests covering intended usage and some edge cases, but it seems there may be a
memory-leak issue with concurrent tasks (I'm not sure if this is a known bug); this test
(task-level abort: works with task concurrency) is skipped. If you can get it working, then
maybe it's just my environment.

I added documentation about the bench-and-task-level-AbortSignal support to README.md. Happy
to remove if it's not needed--or I can remove the examples, or whatever.

boneskull added a commit to boneskull/modestbench that referenced this pull request Oct 18, 2025
@43081j
Copy link
Member

43081j commented Oct 19, 2025

looks like a great change to me!

i'd really love to ditch p-limit, its almost certainly the source of a whole bunch of garbage collection and will be contributing to your memory leak findings. we should be using our own concurrency function given we're a benchmarking library IMO (one we can control and... write better).

what do you think @jerome-benoit ? in a separate PR some time

edit: have opened #365 and it doesn't seem to hit the same OOM exception when i try it locally

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 19, 2025

Open in StackBlitz

npm i https://pkg.pr.new/tinylibs/tinybench@364

commit: e1aff20

@jerome-benoit
Copy link
Collaborator

The feature implementation looks good. Please address the typing issue in tests triggering a CI failure.

Thanks.

Fixes tinylibs#139

This change enables `Task` to be aborted via an `AbortSignal` which falls back to a signal its
`Bench`'s signal.

It adds a `signal` prop to the `Task` class, as well as an `isAborted()` method (which could be a
getter, if you wish).

I'm wrapping `tinybench` and have confirmed this works well, as I'm able to abort (async) tasks via
the signal.

I've added tests covering intended usage and some edge cases, but it seems there may be a
memory-leak issue with concurrent tasks (I'm not sure if this is a known bug); this test
(`task-level abort: works with task concurrency`) is skipped.  If you can get it working, then
maybe it's just my environment.

I added documentation about the bench-and-task-level-`AbortSignal` support to `README.md`.  Happy
to remove if it's not needed--or I can remove the examples, or whatever.
@boneskull boneskull force-pushed the boneskull/issue-139 branch from 419b959 to e1aff20 Compare October 19, 2025 20:25
@boneskull
Copy link
Contributor Author

OK, fixed the type error. Thanks for looking at this so quickly!

Copy link
Collaborator

@jerome-benoit jerome-benoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a single nitpicking review comments to add ;)

@jerome-benoit jerome-benoit merged commit f372161 into tinylibs:main Oct 20, 2025
15 checks passed
@boneskull boneskull deleted the boneskull/issue-139 branch October 20, 2025 21:17
This was referenced Nov 20, 2025
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.

Feature: add abort signal support at the task level

3 participants