### Version v18.12.1 ### Platform Linux ruby 5.15.0-53-generic #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux ### Subsystem Buffer ### What steps will reproduce the bug? Run this under node v18 vs node v16 ```js const randomBuffer = (length) => Buffer.from(Array.from({length}, () => Math.random() * 255)) const testCases = [ {bytesPerBuffer: 32, numBuffers: 10}, ] for (const {bytesPerBuffer, numBuffers} of testCases) { const results = [] for (let i = 0; i < 100_000; i++) { const buffers = Array.from({length: numBuffers}, () => randomBuffer(bytesPerBuffer)) const before = performance.now() Buffer.concat(buffers) const after = performance.now() results.push(after - before) } const avgTime = results.reduce((a, b) => a + b, 0) / results.length console.log(`concat ${numBuffers} buffers, ${bytesPerBuffer} each: ${avgTime}s`) } ``` ### How often does it reproduce? Is there a required condition? Always reproduceable ### What is the expected behavior? Expected behavior is that there is no performance regression. ### What do you see instead? Buffer.concat is ~2.5x slower after node v16 (v17 and beyond) ### Additional information _No response_
Activity
RafaelGSS commentedon Dec 15, 2022
HI @wemeetagain. I've run it locally and it seems fixed in v19. See below:
v14
concat 10 buffers, 32 each: 0.00033s
v16
concat 10 buffers, 32 each: 0.00044s
v18
concat 10 buffers, 32 each: 0.00114s
v19
concat 10 buffers, 32 each: 0.0004s
Note: I haven't investigated the cause, but, I'd wait for the next v18 release and compare.
krk commentedon Dec 30, 2022
I bisected with the help of nvm, found that 17.2.0 introduced the regression. Then profiling with
perfusing this modified reproducer:17.1.0 (good)
17.2.0 (bad)
In 17.2.0,
Builtins_*dominate the call stacks, pointing to a v8 issue.Further bisecting with git identifies #40488, which updates v8 from
9.5.172.25to9.6.180.14as the PR when this regression was introduced.spollack commentedon Feb 10, 2023
Question: is the perf fix likely to be picked up for node 18.x? or will we have to wait for 20.x to have the fix in an LTS? Thank you.
wemeetagain commentedon Oct 10, 2024
appears to be resolved by node 20 (also 22 is good)