Skip to content

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

Merged
crowlKats merged 1 commit into
mainfrom
perf/dep-graph-parallel-metadata
Nov 29, 2026
Merged

crowlKats merged 1 commit into
mainfrom
perf/dep-graph-parallel-metadata

Conversation

@crowlKats

Copy link
Copy Markdown
Member

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.

@crowlKats
crowlKats added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 1539d57 Nov 29, 2026
10 checks passed
@crowlKats
crowlKats deleted the perf/dep-graph-parallel-metadata branch November 29, 2026 05:50
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.

2 participants