⚡ Optimize analysis data loading with iterators#25
Conversation
- Add `getPagesIteratorBySnapshot` to `PageRepository` using `better-sqlite3`'s `.iterate()`. - Update `loadCrawlData` in `analyze.ts` to stream pages from DB instead of loading all into memory. - Refactor `analyzePages` to accept `Iterable<CrawlPage>` and use a single-pass loop for analysis. - Maintain duplicate detection logic using accumulated frequency maps. - Significantly reduce memory footprint for large crawls.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Replaced the array-based data loading in
analyzeSitewith an iterator-based approach.getPagesIteratorBySnapshottoPageRepositorywhich usesbetter-sqlite3's.iterate()to stream rows.loadCrawlDatato yield pages lazily.analyzePagesto consume an iterator and perform analysis in a single pass (plus a second pass over lightweight result objects for status finalization).🎯 Why:
Loading all pages (especially with HTML content) into an array causes massive memory spikes for large sites. Streaming pages allows processing them one by one, keeping memory usage proportional to the size of a single page (plus analysis metadata) rather than the entire dataset.
📊 Measured Improvement:
Benchmark with 10,000 pages (10KB HTML each):
PR created automatically by Jules for task 7904780795355805909 started by @saurabhsharma2u