mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
perf: amortize handle iterator (#10002)
This commit is contained in:
parent
dba1b2d9cc
commit
ab27f738c9
@ -29,7 +29,7 @@ const DEFAULT_BATCH_SIZE = 20;
|
|||||||
*/
|
*/
|
||||||
async function* fastTransposeIteratorHandle<T>(
|
async function* fastTransposeIteratorHandle<T>(
|
||||||
iterator: JSHandle<AwaitableIterator<T>>,
|
iterator: JSHandle<AwaitableIterator<T>>,
|
||||||
size = DEFAULT_BATCH_SIZE
|
size: number
|
||||||
) {
|
) {
|
||||||
const array = await iterator.evaluateHandle(async (iterator, size) => {
|
const array = await iterator.evaluateHandle(async (iterator, size) => {
|
||||||
const results = [];
|
const results = [];
|
||||||
@ -56,8 +56,11 @@ async function* fastTransposeIteratorHandle<T>(
|
|||||||
async function* transposeIteratorHandle<T>(
|
async function* transposeIteratorHandle<T>(
|
||||||
iterator: JSHandle<AwaitableIterator<T>>
|
iterator: JSHandle<AwaitableIterator<T>>
|
||||||
) {
|
) {
|
||||||
|
let size = DEFAULT_BATCH_SIZE;
|
||||||
try {
|
try {
|
||||||
while (!(yield* fastTransposeIteratorHandle(iterator))) {}
|
while (!(yield* fastTransposeIteratorHandle(iterator, size))) {
|
||||||
|
size <<= 1;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
await iterator.dispose();
|
await iterator.dispose();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user