Skip to content

deps: V8: cherry-pick 25650aa994 - #66500

Open
nigrosimone wants to merge 1 commit into
nodejs:mainfrom
nigrosimone:v8-microtask-early-exit
Open

nigrosimone wants to merge 1 commit into
nodejs:mainfrom
nigrosimone:v8-microtask-early-exit

Conversation

@nigrosimone

Copy link
Copy Markdown
Contributor

Cherry-pick of v8/v8@25650aa994 (V8 15.4): an empty microtask checkpoint returns early, when there is no completed callback and no WeakRef kept during the job.

Node runs a checkpoint after every top-level callback and the queue is usually empty there, so node::MakeCallback goes from 132.9 to 121.9 ns.

benchmark/compare.js, napi/make_callback with the type cases of #66326, 30 runs, Linux x64, one core, same V8 14.6.202.34 as main:

                                                     confidence improvement accuracy (*)   (**)  (***)
napi/make_callback n=1000000 type='AsyncResource'           ***      9.45 %  ±3.54% ±4.72% ±6.16%
napi/make_callback n=1000000 type='Call'                            -4.06 %  ±6.47% ±8.65% ±11.32%
napi/make_callback n=1000000 type='MakeCallback'             **      8.00 %  ±5.69% ±7.58% ±9.88%
napi/make_callback n=10000000 type='AsyncResource'           **      5.91 %  ±3.43% ±4.56% ±5.94%
napi/make_callback n=10000000 type='Call'                            1.64 %  ±5.49% ±7.30% ±9.51%
napi/make_callback n=10000000 type='MakeCallback'           ***      9.05 %  ±2.59% ±3.44% ±4.48%

type=Call runs no checkpoint per call, and the same binary against itself stays inside ±2.4% with no stars. The async_hooks, ALS, microtask, WeakRef, FinalizationRegistry, promise and timers tests give the same result as without it.

Refs: nodejs/performance#24

Disclosure: I used Opus 5.5 (Max) as coding assistant

Original commit message:

    [microtask] Early-exit empty PerformCheckpointInternal and OnCompleted

    Microtask checkpoints (MicrotaskQueue::PerformCheckpoint) are executed
    frequently at the end of every DOM event listener, microtask scope exit,
    timer callback, and mutation observer turn.

    In typical DOM interactions and event dispatch cycles, the microtask
    queue is frequently empty (size_ == 0), no microtask completion
    callbacks are registered, and no weak references were kept during the
    job (weak_refs_keep_during_job == undefined_value()).

    Previously, even when the queue was empty, PerformCheckpointInternal
    unconditionally allocated an artificial
    MicrotasksScope(kDoNotRunMicrotasks), called RunMicrotasks (which set
    running state flags, created suppress scopes, and rewound entered
    contexts), invoked OnCompleted, and called isolate->ClearKeptObjects()
    (performing an unconditional store to the weak_refs_keep_during_job root
    table slot).

    This CL fast-paths PerformCheckpointInternal when size() == 0,
    microtasks_completed_callbacks_ is empty, and weak_refs_keep_during_job
    is undefined. If WeakRef.prototype.deref() was invoked during the turn,
    weak_refs_keep_during_job holds an OrderedHashSet, so the early-exit is
    skipped and ClearKeptObjects() runs to clear kept objects as required by
    ECMAScript §26.1.

    Pinpoint Try Job on Apple Silicon M1 (150 iterations, Job
    158c2910690000):
    - Speedometer 3 Score: 31.42 -> 31.48 (+0.21%, p=0.0293, stat-sig win)
    - TodoMVC-JavaScript-ES6-Webpack: -0.87% (p=0.0001)
    - NewsSite-Nuxt: -0.40% (p=0.0001)
    - TodoMVC-Angular: -0.45% (p=0.0681)
    - TodoMVC-jQuery: -0.36% (p=0.6023)
    - Charts-chartjs: -0.21% (p=0.0005)
    - React-Stockcharts-SVG: -0.26% (p=0.0144)

    Bug: 553846289
    TAG=agy
    CONV=a3721850-14cb-425b-8d34-169f9934ed78

    Change-Id: Ic996d283b746a5684a55c9fbc56d8fcfb38ac299
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8312487
    Commit-Queue: Anton Bikineev <bikineev@chromium.org>
    Auto-Submit: Anton Bikineev <bikineev@chromium.org>
    Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#109567}

Refs: v8/v8@25650aa
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/security-wg
  • @nodejs/v8-update

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to Node.js builds or CI infrastructure. needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency. labels Oct 4, 2026
@nigrosimone
nigrosimone marked this pull request as ready for review October 4, 2026 06:15
@anonrig anonrig 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 Oct 4, 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. build Issues and PRs related to Node.js builds or CI infrastructure. needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. v8 engine Issues and PRs related to the V8 dependency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants