Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

perf(core): improve `RequestList` initialization speed on large arrays (#3754)

Rayan Salhabc451c13a9c9b
diff --git a/packages/core/src/storages/request_list.ts b/packages/core/src/storages/request_list.ts
index 4e6a09741..2c0736f9b 100644
--- a/packages/core/src/storages/request_list.ts
+++ b/packages/core/src/storages/request_list.ts
@@ -488,9 +488,12 @@ export class RequestList implements IRequestList {
const sourcesFromFunction = await this.sourcesFunction();
const sourcesFromFunctionCount = sourcesFromFunction.length;
for (let i = 0; i < sourcesFromFunctionCount; i++) {
- const source = sourcesFromFunction.shift();
- this._addRequest(source!);
+ const source = sourcesFromFunction[i];
+ delete sourcesFromFunction[i];
+ this._addRequest(source);
}
+
+ sourcesFromFunction.length = 0;
} catch (e) {
const err = e as Error;
throw new Error(`Loading requests with sourcesFunction failed.\nCause: ${err.message}`);