Skip to content

stream: cache minimum cursor count in share - #63262

Merged
nodejs-github-bot merged 4 commits into
nodejs:mainfrom
trivikr:streams-iter-share
May 14, 2026
Merged

stream: cache minimum cursor count in share#63262
nodejs-github-bot merged 4 commits into
nodejs:mainfrom
trivikr:streams-iter-share

Conversation

@trivikr

@trivikrtrivikr commented May 12, 2026

Copy link
Copy Markdown
Member

Description

This updates share() and shareSync() to avoid recomputing the minimum
consumer cursor on every buffer trim attempt.

Instead of scanning all consumers each time, share now caches the current
minimum cursor and tracks how many consumers are positioned at that
cursor. The minimum is recomputed only when the last consumer at the
cached minimum advances or detaches.

The shared getMinCursor() utility now returns both the minimum cursor
and the number of consumers at that cursor.

Benchmark

 confidence improvement accuracy (*) (**) (***)streams/iter-throughput-share.js n=5 backpressure='block' batches=10000 consumers=2 *** 6.06 % ±2.01% ±2.76% ±3.76%streams/iter-throughput-share.js n=5 backpressure='block' batches=10000 consumers=32 *** 69.76 % ±1.56% ±2.15% ±2.96%streams/iter-throughput-share.js n=5 backpressure='block' batches=10000 consumers=8 *** 20.96 % ±1.71% ±2.38% ±3.35%

Assisted-by: openai:gpt-5.5

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance
  • @nodejs/streams

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels May 12, 2026
@trivikr
trivikrforce-pushed the streams-iter-share branch 2 times, most recently from a0ce67e to 8a32f1cCompareMay 12, 2026 06:51
@trivikr

This comment was marked as outdated.

Comment threadlib/internal/streams/iter/broadcast.js Outdated
Comment threadlib/internal/streams/iter/share.js Outdated
Comment threadlib/internal/streams/iter/share.js Outdated
Comment threadlib/internal/streams/iter/share.js
@trivikr
trivikr marked this pull request as ready for review May 12, 2026 08:02
@codecov

codecovBot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.15625% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.05%. Comparing base (c24e552) to head (f843e46).
⚠️ Report is 5 commits behind head on main.

Files with missing linesPatch %Lines
lib/internal/streams/iter/share.js83.33%19 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #63262 +/- ##
=======================================
Coverage 90.05% 90.05% =======================================
Files 714 714 Lines 225247 225338 +91 Branches 42578 42597 +19 =======================================
+ Hits 202842 202930 +88 - Misses 14181 14190 +9 + Partials 8224 8218 -6 
Files with missing linesCoverage Δ
lib/internal/streams/iter/broadcast.js84.66% <100.00%> (+0.02%)⬆️
lib/internal/streams/iter/utils.js100.00% <100.00%> (ø)
lib/internal/streams/iter/share.js84.12% <83.33%> (-0.06%)⬇️

... and 33 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.

@trivikrtrivikr self-assigned this May 12, 2026
@trivikrtrivikr added the request-ci Add this label to start a Jenkins CI on a PR. label May 12, 2026
trivikr added 4 commits May 13, 2026 08:20
Track the number of consumers at the cached minimum cursor in share()
so the minimum is only recomputed when the last consumer at that cursor
advances or detaches.
This avoids scanning every consumer on each trim attempt when multiple
consumers advance through a shared buffer.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
@trivikr
trivikrforce-pushed the streams-iter-share branch from 2eda9ba to f843e46CompareMay 13, 2026 15:20
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 14, 2026
@nodejs-github-bot

This comment was marked as outdated.

@trivikrtrivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 14, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikrtrivikr added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. commit-queue Add this label to land a pull request using GitHub Actions. labels May 14, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 14, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 2edd842 into nodejs:mainMay 14, 2026
77 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 2edd842

@trivikr
trivikr deleted the streams-iter-share branch May 14, 2026 21:02
aduh95 pushed a commit that referenced this pull request May 19, 2026
Track the number of consumers at the cached minimum cursor in share()
so the minimum is only recomputed when the last consumer at that cursor
advances or detaches.
This avoids scanning every consumer on each trim attempt when multiple
consumers advance through a shared buffer.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63262
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
aduh95 pushed a commit that referenced this pull request May 19, 2026
Track the number of consumers at the cached minimum cursor in share()
so the minimum is only recomputed when the last consumer at that cursor
advances or detaches.
This avoids scanning every consumer on each trim attempt when multiple
consumers advance through a shared buffer.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63262
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
aduh95 pushed a commit to aduh95/node that referenced this pull request Jul 30, 2026
Track the number of consumers at the cached minimum cursor in share()
so the minimum is only recomputed when the last consumer at that cursor
advances or detaches.
This avoids scanning every consumer on each trim attempt when multiple
consumers advance through a shared buffer.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: nodejs#63262
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@trivikr@nodejs-github-bot@jasnell@Renegade334