← Back to Pull requests

perf(api): fetch dependency graph metadata concurrently on the worker #1606

Closed
unknown closed this pull request without merging on Nov 29, 2026 05:49 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 00:24 UTC
Author

GET /api/scopes/:scope/packages/:package/versions/:version/dependencies/graph is still slow on the worker. This makes it faster without using more memory.

Cause

On wasm32, deno_graph's default Executor doesn't spawn anything. It returns each future without starting it. resolve_pending_jsr_specifiers then awaits each pending meta.json, and then each <version>_meta.json, one after another. Every metadata fetch at a level of the dependency tree became its own R2 round trip in series: a level with 10 dependencies costs ~20 sequential round trips instead of ~2.

Natively the default executor does spawn, so this never showed up in tests or in the earlier work (#1543).

Changes

  • Concurrent metadata loads on the worker: a wasm-only DepTreeExecutor spawns each load with tokio::spawn + AssertSend (the same pattern spawn_blocking uses on the worker). It keeps the current span so R2 binding spans still nest correctly. The native build is unchanged.

  • Lighter dependency metadata parse: the loader re-read each dependency's <version>_meta.json as a full VersionMetadata. That builds a whole serde_json::Value tree plus every ModuleInfo, only to read exports, manifest sizes and module keys. It now deserializes a small struct that skips the module graph contents with IgnoredAny.

  • No copies on cache hits: RegistryMetadataCache stores Arc<[u8]>, the type deno_graph takes, so a hit goes into the graph without a copy (before, it was copied twice via to_vec().into()). Other loads go from two copies to one.

  • No end-of-build clones: the size and fallback-package maps were cloned in full after the build; now they're moved out with mem::take. This also replaces Arc::into_inner(..).unwrap() on exports, which could panic if a spawned task still held a clone.
  • Memory goes down: fewer copies, no per-dependency Value tree, no map clones. Concurrency doesn't hold any more documents than before.

    Behaviour change

    A dependency's metadata with neither moduleGraph2 nor moduleGraph1 used to fail the whole graph. Now it loads, and its files are treated as needing a download.

    Tests

    cargo check/clippy are clean for native and wasm32-unknown-emscripten, and all 162 registry_api tests pass. The executor change only applies on wasm, so the tests don't exercise it and the speedup isn't measured yet. Staging traces of this endpoint, before and after, should show it.

    Not addressed

    The handler's parse of the root package's VersionMetadata still goes through serde_json::Value, once per request. Fixing it means changing the shared deserializer, which other code also uses.

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: littledivy Review duration: 325m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.42) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 334 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1606"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.2% · Safe to merge
    18.2%
    Repository