Skip to content

Commit ab27f73

Browse files
authored
perf: amortize handle iterator (#10002)
1 parent dba1b2d commit ab27f73

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/puppeteer-core/src/common/HandleIterator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const DEFAULT_BATCH_SIZE = 20;
2929
*/
3030
async function* fastTransposeIteratorHandle<T>(
3131
iterator: JSHandle<AwaitableIterator<T>>,
32-
size = DEFAULT_BATCH_SIZE
32+
size: number
3333
) {
3434
const array = await iterator.evaluateHandle(async (iterator, size) => {
3535
const results = [];
@@ -56,8 +56,11 @@ async function* fastTransposeIteratorHandle<T>(
5656
async function* transposeIteratorHandle<T>(
5757
iterator: JSHandle<AwaitableIterator<T>>
5858
) {
59+
let size = DEFAULT_BATCH_SIZE;
5960
try {
60-
while (!(yield* fastTransposeIteratorHandle(iterator))) {}
61+
while (!(yield* fastTransposeIteratorHandle(iterator, size))) {
62+
size <<= 1;
63+
}
6164
} finally {
6265
await iterator.dispose();
6366
}

0 commit comments

Comments
 (0)