FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

buffer: simplify Buffer.concat by gibson042 · Pull Request #64836 · nodejs/node · GitHub

/ node Public

buffer: simplify Buffer.concat - #64836

Open
gibson042 wants to merge 1 commit into
nodejs:mainfrom
gibson042:2026-07-simplify-buffer-concat
Open

buffer: simplify Buffer.concat#64836
gibson042 wants to merge 1 commit into
nodejs:mainfrom
gibson042:2026-07-simplify-buffer-concat

Conversation

Copy link
Copy Markdown
Contributor

Merge the auto-length and explicit-length paths of Buffer.concat while maintaining the branch-free status of the copy loop body from #61721 by discovering the the index of the first not-fully-copyable input inside the validation loop.

Also improve efficiency by relying upon TypedArrayPrototypeGetByteLength for input validation and capturing positions from it.

The end result is more unified code whose performance seems to be roughly equivalent and perhaps slightly skewed in favor of unspecified length:

$ node-benchmark-compare <(
  node benchmark/compare.js --old ./node-upstream --new ./out/Release/node --filter buffer-concat buffers
)
                                                                            confidence improvement accuracy (*)   (**)  (***)
buffers/buffer-concat-fill.js n=800000 extraSize=1                                         -2.84 %       ±2.91% ±3.87% ±5.03%
buffers/buffer-concat-fill.js n=800000 extraSize=1024                                *      3.27 %       ±3.06% ±4.08%  ±5.31%
buffers/buffer-concat-fill.js n=800000 extraSize=256                                       -1.75 %       ±1.94% ±2.59% ±3.37%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=16          ***      7.32 %       ±1.51% ±2.03% ±2.69%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=4                    1.71 %       ±3.48% ±4.68% ±6.18%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=16         ***      6.54 %       ±0.56% ±0.75% ±0.98%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=4          ***      6.03 %       ±1.11% ±1.48% ±1.95%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=16                -2.18 %       ±2.93% ±3.90% ±5.08%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=4         ***     11.32 %       ±3.71% ±4.98% ±6.58%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=16          ***     -5.06 %       ±0.65% ±0.87% ±1.14%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=4           ***     -7.62 %       ±1.33% ±1.77%  ±2.31%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=16         ***     -5.84 %       ±0.70% ±0.93% ±1.22%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=4          ***     -5.99 %       ±0.94% ±1.26% ±1.64%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=16        ***     -8.78 %       ±2.66% ±3.55% ±4.64%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=4         ***     -4.70 %       ±1.67% ±2.22% ±2.90%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 15 comparisons, you can thus expect the following amount of false-positive results:
  0.75 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.15 false positives, when considering a   1% risk acceptance (**, ***),
  0.01 false positives, when considering a 0.1% risk acceptance (***)

nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. labels Jul 30, 2026
Signed-off-by: Richard Gibson <richard.gibson@gmail.com>
gibson042 force-pushed the 2026-07-simplify-buffer-concat branch from bef937d to 23a8bca Compare July 30, 2026 08:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL