Skip to content

Commit cfad2ef

Browse files
mcollinaaduh95
authored andcommitted
stream: use the ring buffer for pending BYOB pull-into descriptors
The byte controller's [[pendingPullIntos]] list was still a plain array consumed with ArrayPrototypeShift, while every other per-chunk queue in the WHATWG streams implementation has moved to the Queue ring buffer. BYOB reads push and shift one descriptor per read, and Array.prototype shift has real per-call cost even at length 1. Back the descriptor list with the same lazily materialized Queue used for the request queues, so constructing a byte stream still allocates no descriptor storage. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #64818 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent 9d2f10e commit cfad2ef

3 files changed

Lines changed: 164 additions & 86 deletions

File tree

‎benchmark/webstreams/tee.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
const{ ReadableStream }=require('node:stream/web');
4+
5+
constbench=common.createBenchmark(main,{
6+
n: [1e5],
7+
type: ['normal','bytes'],
8+
});
9+
10+
asyncfunctionmain({ n, type }){
11+
leti=0;
12+
constsource=type==='bytes' ?
13+
{
14+
type: 'bytes',
15+
pull(controller){
16+
if(i++<n)controller.enqueue(newUint8Array(16));
17+
elsecontroller.close();
18+
},
19+
} :
20+
{
21+
pull(controller){
22+
if(i++<n)controller.enqueue('a');
23+
elsecontroller.close();
24+
},
25+
};
26+
27+
constrs=newReadableStream(source);
28+
const[branch1,branch2]=rs.tee();
29+
constreader1=branch1.getReader();
30+
constreader2=branch2.getReader();
31+
letreads=0;
32+
33+
bench.start();
34+
for(;;){
35+
const[result1,result2]=awaitPromise.all([
36+
reader1.read(),
37+
reader2.read(),
38+
]);
39+
if(result1.done||result2.done)break;
40+
reads++;
41+
}
42+
bench.end(reads);
43+
console.assert(reads===n);
44+
}

0 commit comments

Comments
 (0)