Skip to content

Commit

Permalink
perf: amortize handle iterator (#10002)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Apr 11, 2023
1 parent dba1b2d commit ab27f73
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/puppeteer-core/src/common/HandleIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const DEFAULT_BATCH_SIZE = 20;
*/
async function* fastTransposeIteratorHandle<T>(
iterator: JSHandle<AwaitableIterator<T>>,
size = DEFAULT_BATCH_SIZE
size: number
) {
const array = await iterator.evaluateHandle(async (iterator, size) => {
const results = [];
Expand All @@ -56,8 +56,11 @@ async function* fastTransposeIteratorHandle<T>(
async function* transposeIteratorHandle<T>(
iterator: JSHandle<AwaitableIterator<T>>
) {
let size = DEFAULT_BATCH_SIZE;
try {
while (!(yield* fastTransposeIteratorHandle(iterator))) {}
while (!(yield* fastTransposeIteratorHandle(iterator, size))) {
size <<= 1;
}
} finally {
await iterator.dispose();
}
Expand Down

0 comments on commit ab27f73

Please sign in to comment.