Skip to content

lib: stop refreshing composite AbortSignals - #67543

Open
ronag wants to merge 1 commit into
nodejs:mainfrom
ronag:abort-signal-throw-if-aborted
Open

ronag wants to merge 1 commit into
nodejs:mainfrom
ronag:abort-signal-throw-if-aborted

Conversation

@ronag

@ronag ronag commented Nov 17, 2026

Copy link
Copy Markdown
Member

Since #66014, AbortSignal.any() follows its sources as soon as it creates a composite, so aborting a source aborts every composite that follows it right away. The aborted and reason getters and throwIfAborted() still walked the composite's sources on every call. Profiling throwIfAborted() on a two-source composite put 91% of the time in that walk, most of it in WeakRef.prototype.deref(), which adds its target to the kept objects of the current job.

That walk can't find anything anymore: a composite is always aborted by the time one of its sources is. So this removes refreshCompositeSignal() and adds a benchmark for throwIfAborted(). test-abortsignal-any-source-gc already checks each accessor after a source has been aborted and collected.

node benchmark/abort_controller/abort-signal-throw-if-aborted.js, release builds of main and this branch, Linux x64, 30 interleaved runs per binary:

kind improvement 95% CI
controller 7.38% ± 3.84%
timeout 6.84% ± 3.04%
any 1652.02% ± 37.91%
mixed 430.80% ± 12.60%

The aborted getter gets the same speedup. In the existing abort_controller benchmarks, any with listen is 7% faster and addAbortListener is 2-3.5% slower. Its optimized code is the same apart from the removed check (same inlining, no deopts), so I think that one is code layout, but it shows up consistently.

AbortSignal.any() follows its sources as soon as it creates a
composite, so aborting a source synchronously aborts every composite
that follows it. The aborted and reason getters and throwIfAborted()
still walked the composite's sources on every call and dereferenced
the WeakRef of each one, which is expensive because
WeakRef.prototype.deref() adds its target to the kept objects of the
current job.

That walk can no longer find an aborted source of a composite that
isn't aborted itself, so remove it. throwIfAborted() on a composite
with two sources becomes about 17 times faster, the same as on a
plain signal.

Add a benchmark for throwIfAborted() on plain, timeout, composite and
mixed signals.

Assisted-by: claude:opus-5.5
Signed-off-by: Robert Nagy <ronagy@icloud.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Nov 17, 2026
@ronag
ronag requested a balanced review from Copilot November 17, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the removal of redundant composite AbortSignal source checks.

No open issues 🎉

What changed in this PR

Builds on the eager abort propagation introduced in #66014 to remove redundant source checks when reading composite AbortSignal state.

Changes:

  • Removes refreshCompositeSignal() and its calls from accessors, throwIfAborted(), and composite construction.
  • Adds a throwIfAborted() benchmark covering controller, timeout, composite, and mixed signals.
File Description
lib/​internal/​abort_controller.js Removes source refreshes and documents why composite abort state stays current.
benchmark/​abort_controller/​abort-signal-throw-if-aborted.js Adds performance coverage for repeated non-aborted signal checks.

Review effort: Balanced

@ronag
ronag marked this pull request as ready for review November 17, 2026 14:11
@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 17, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.67%. Comparing base (bc6dd40) to head (09420b4).
⚠️ Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67543      +/-   ##
==========================================
- Coverage   90.67%   90.67%   -0.01%     
==========================================
  Files         800      800              
  Lines      280489   280912     +423     
  Branches    54166    54280     +114     
==========================================
+ Hits       254336   254716     +380     
- Misses      16277    16296      +19     
- Partials     9876     9900      +24     
Files with missing lines Coverage Δ
lib/internal/abort_controller.js 96.42% <100.00%> (+1.01%) ⬆️

... and 50 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 17, 2026
@github-actions github-actions Bot added request-ci-failed Starting CI with the request-ci label failed and requires manual intervention. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Failed to start CI

   ℹ  Existing CI run found: https://ci.nodejs.org/job/node-test-pull-request/79215/
   ✖  Refusing to start a potentially duplicate CI job. The existing CI run is still in progress.
Full Auto Start CI output
�[36m⠋�[39m Getting reviews from nodejs/node/pull/67543
�[36m⠋�[39m Getting commits from nodejs/node/pull/67543
�[36m⠙�[39m Validating Jenkins credentials
�[36m⠙�[39m Validating Jenkins credentials
✔  Jenkins credentials valid
�[36m⠹�[39m Getting comments from nodejs/node/pull/67543
�[36m⠸�[39m Querying data for job/node-test-pull-request/79215/
�[36m⠸�[39m Querying data for job/node-test-pull-request/79215/
�[36m⠸�[39m Querying API for job/node-test-pull-request/79215/
✔  Build data downloaded
   ℹ  Existing CI run found: https://ci.nodejs.org/job/node-test-pull-request/79215/
   ✖  Refusing to start a potentially duplicate CI job. The existing CI run is still in progress.

View workflow run

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@ronag ronag added commit-queue PRs queued for automated landing through the Commit Queue. and removed request-ci-failed Starting CI with the request-ci label failed and requires manual intervention. labels Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants