⚡ Bolt: [performance improvement] Replace getEdges() with memory-efficient forEachEdge()#100
Conversation
… paths - Added `forEachEdge` to Graph to iterate edges without array allocations - Refactored `hits.ts`, `pagerank.ts`, and `metrics.ts` to use `forEachEdge` - Updated `metrics.ts` to use `graph.edges.size` instead of mapping edges - Verified HITS and PageRank tests to ensure functional correctness and benchmark improvement
|
👋 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: Implemented a new
forEachEdgemethod on theGraphclass that iterates directly over the internaledgesMap and decodes the composite key inline. Replaced all performance-critical usages ofgraph.getEdges()withgraph.forEachEdge(...)inhits.ts,pagerank.ts, andmetrics.ts.🎯 Why: Calling
graph.getEdges()inside these hot loops caused massive array and object allocations (creating an array of{source, target, weight}objects for every edge in the graph), leading to significant garbage collection overhead, especially for massive site graphs.📊 Impact: Reduces heap memory usage substantially during PageRank and HITS calculations, making the application measurably faster and more efficient on large datasets by avoiding full array allocations.
🔬 Measurement: Run
pnpm --filter core testto verify functional correctness and see the benchmark outputs frompagerank_perf_large.test.tsandhits_perf_large.test.ts.PR created automatically by Jules for task 12845013787333598539 started by @saurabhsharma2u