Skip to content

Conversation

@gurgunday
Copy link
Member

This PR adds an early return for when the passed list to concat has buffers with length 0, it increases the speed of this specific case significantly while not having a significant effect on other cases, the check is done once

Before

buffers/buffer-concat.js
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=0 pieces=4: 21,154,950.27952036
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=0 pieces=4: 19,196,794.135379393
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=4: 6,989,916.337953473
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=4: 6,865,887.074369392
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=4: 6,721,592.326401666
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=4: 6,556,017.96516101
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=4: 4,483,340.537034144
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=4: 4,402,483.275722712
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=0 pieces=16: 11,026,637.420164905
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=0 pieces=16: 11,842,107.639370283
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=16: 2,236,282.0692457757
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=16: 2,303,720.328352138
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=16: 2,131,347.3893047236
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=16: 2,188,456.664168826
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=16: 990,001.0414563456
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=16: 1,006,497.9406397911

After

buffers/buffer-concat.js
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=0 pieces=4: 29,413,341.347488407 +
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=0 pieces=4: 29,923,787.106618155 +
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=4: 6,840,184.125444326
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=4: 6,860,703.071986998
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=4: 6,595,750.911730649
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=4: 6,687,702.724123686
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=4: 4,516,053.166206851
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=4: 4,397,381.275899957
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=0 pieces=16: 22,975,191.35965086 +
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=0 pieces=16: 29,982,993.646003988 +
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=16: 2,235,451.225159163
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=16: 2,262,244.3089532913
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=16: 2,131,322.3142175823
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=16: 2,163,427.3286168366
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=16: 995,333.8537428093
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=16: 991,416.6050230672

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. labels Oct 24, 2025
@gurgunday gurgunday added the performance Issues and PRs related to the performance of Node.js. label Oct 24, 2025
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.56%. Comparing base (2bda7cb) to head (9c655ac).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60393      +/-   ##
==========================================
- Coverage   88.56%   88.56%   -0.01%     
==========================================
  Files         704      704              
  Lines      207774   207777       +3     
  Branches    40025    40033       +8     
==========================================
- Hits       184022   184018       -4     
- Misses      15807    15811       +4     
- Partials     7945     7948       +3     
Files with missing lines Coverage Δ
lib/buffer.js 99.12% <100.00%> (-0.88%) ⬇️

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

@gurgunday
Copy link
Member Author

Oops, this breaks

Let me try something simpler

@gurgunday gurgunday closed this Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants