⚡ Optimize Post-Crawl Metrics with Batch Pre-fetching#28
Conversation
|
👋 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. |
- Pre-fetch all pages and existing metrics for the snapshot into memory maps. - Replace individual database lookups in the main loop with map lookups. - Move prepared statement creation for clusters outside the transaction. - Significantly reduces database round-trips from 2N+C to 2+C for reads.
27911d2 to
e2fdbc3
Compare
|
Review complete ✅. PR aligns correctly with Performance and Scale from our roadmap by addressing the N+1 query issue in post-crawl metrics calculations. During rebase conflict resolution, I verified that |
⚡ Performance Optimization: N+1 Query in Post-Crawl Metrics
💡 What
This PR optimizes the
runPostCrawlMetricsfunction inplugins/core/src/crawler/metricsRunner.tsby implementing a pre-fetching strategy.Mapobjects.db.preparecalls outside of the processing transaction to avoid redundant statement preparation.🎯 Why
The previous code pattern was a classic N+1 query issue. For every node in the graph, it performed:
pageRepo.getIdByUrlmetricsRepo.getMetricsForPageIn a crawl with 1,000 nodes, this resulted in 2,000 additional
SELECTqueries. This was a significant bottleneck in the post-crawl analysis phase.📊 Measured Improvement
Direct benchmarking in the sandbox was limited by environment constraints (missing
better-sqlite3and no internet access). However, the optimization is theoretically sound:This change ensures that post-crawl processing time remains efficient even as the number of crawled pages grows.
PR created automatically by Jules for task 3643971261105437581 started by @saurabhsharma2u