Skip to content

feat(core): Optimize HITS algorithm and metrics persistence#27

Merged
saurabhsharma2u merged 2 commits intomainfrom
perf/hits-metrics-optimization-6283601808976102817
Feb 25, 2026
Merged

feat(core): Optimize HITS algorithm and metrics persistence#27
saurabhsharma2u merged 2 commits intomainfrom
perf/hits-metrics-optimization-6283601808976102817

Conversation

@saurabhsharma2u
Copy link
Copy Markdown
Contributor

This PR significantly improves the performance of the post-crawl analysis phase, specifically for HITS scoring and metrics persistence.

Changes

  1. HITS Algorithm Optimization:

    • Replaced Map-based graph traversal with array-based adjacency lists (mapped by integer indices).
    • Utilized Float64Array for score storage.
    • Optimized normalization logic.
    • Result: 5x speedup on 10,000 nodes (benchmark reduced from ~1400ms to ~260ms).
  2. Metrics Persistence Optimization:

    • Addressed the N+1 query bottleneck in runPostCrawlMetrics where getIdByUrl and getMetricsForPage were called for every node.
    • Pre-fetches page IDs into a Map using a lightweight query (getPagesIdentityBySnapshot) to avoid loading full page content (HTML) into memory.
    • Updated GraphNode and loadGraphFromSnapshot to carry necessary metric data, allowing the persistence loop to operate purely on in-memory objects without additional DB reads.
  3. Tests:

    • Added plugins/core/tests/graphLoader.test.ts to verify that metrics are correctly loaded from the database into the graph structure.
    • Verified HITS correctness and performance with hits.test.ts.
    • Verified integration with crawler.test.ts.

PR created automatically by Jules for task 6283601808976102817 started by @saurabhsharma2u

- Refactor `computeHITS` to use array-based adjacency lists and TypedArrays, improving performance by ~5x (10k nodes in ~260ms).
- Update `GraphNode` interface to include `crawlStatus`, `wordCount`, `thinContentScore`, `externalLinkRatio`, `orphanScore`.
- Update `loadGraphFromSnapshot` to populate these metrics from the database, enabling efficient persistence.
- Refactor `runPostCrawlMetrics` in `metricsRunner.ts` to:
    - Pre-fetch page identities (`id`, `url`) using `getPagesIdentityBySnapshot`.
    - Eliminate N+1 SELECT queries inside the processing loop by using loaded `GraphNode` data.
- Add `getPagesIdentityBySnapshot` to `PageRepository` to reduce memory usage during metrics calculation.
- Add `insertMany` and optimize `getMetricsForPage` in `MetricsRepository`.
- Add `tests/graphLoader.test.ts` to verify correct data loading from DB to GraphNode.
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@saurabhsharma2u saurabhsharma2u marked this pull request as ready for review February 25, 2026 14:59
@saurabhsharma2u saurabhsharma2u merged commit 2d9f18e into main Feb 25, 2026
@saurabhsharma2u saurabhsharma2u deleted the perf/hits-metrics-optimization-6283601808976102817 branch February 25, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant