Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: amortize handle iterator #10002

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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