Skip to content

perf(pm): skip binary mirror lookup for npm registry#2852

Closed
killagu wants to merge 1 commit into
nextfrom
agent/egg-dev/0e8f1ac6
Closed

perf(pm): skip binary mirror lookup for npm registry#2852
killagu wants to merge 1 commit into
nextfrom
agent/egg-dev/0e8f1ac6

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented Apr 27, 2026

Summary:

  • Skip binary mirror config loading during package binary updates when the active registry is the official npm registry.
  • Avoids an unnecessary registry request in npmjs pm-bench install/link phases.

Verification:

  • cargo build -p utoo-pm --release
  • cargo test -p utoo-pm service::binary -- --nocapture
  • BENCH_RUNS=1 PM_LIST=utoo PROJECT=ant-design REGISTRY=https://registry.npmjs.org PATH=/home/killa/multica_workspaces/56c053c2-a029-45bb-a3f8-c83499005c8a/0e8f1ac6/workdir/utoo/target/release:/home/killa/.local/bin:/home/killa/multica_workspaces/56c053c2-a029-45bb-a3f8-c83499005c8a/0e8f1ac6/codex-home/tmp/arg0/codex-arg01UKLE1:/home/killa/.npm-global/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/path:/home/killa/.local/bin:/home/killa/.local/bin:/home/killa/.npm-global/bin:/home/killa/.cargo/bin:/home/killa/.local/bin:/home/killa/.nvm/versions/node/v22.22.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/snap/bin:/home/killa/.local/share/JetBrains/Toolbox/scripts:/home/killa/.local/share/JetBrains/Toolbox/scripts bash bench/pm-bench-phases.sh

Benchmark slice:

  • p0 full cold: 11.81s
  • p1 resolve: 5.08s
  • p3 cold install: 9.97s
  • p4 warm link: 1.07s, netRX 19KB

Risk: mirror rewriting is unchanged for npmmirror and other non-npm registries.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a check to skip binary mirror updates in the update_package_binary function. A review comment identifies a potential race condition where should_skip_binary_mirror() might cache a stale value before registry initialization, and suggests an alternative implementation to ensure the check is performed correctly.

Comment on lines +236 to +238
if should_skip_binary_mirror() {
return Ok(());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using should_skip_binary_mirror() here can lead to a race condition. Because it uses std::sync::OnceLock, it might cache a stale value if called before the async registry initialization is complete. This could cause it to incorrectly attempt a binary mirror lookup against the official npm registry.

To fix this, I suggest performing the check directly here. This avoids the caching issue, and the performance impact should be minimal. I've also preserved the debug logging from the original function.

A more comprehensive fix would be to make should_skip_binary_mirror async and use tokio::sync::OnceCell, which would solve this for all call sites.

Suggested change
if should_skip_binary_mirror() {
return Ok(());
}
let registry = get_registry();
if is_npm_registry(&registry) {
tracing::debug!("Skipping binary mirror update for npm registry: {}", registry);
return Ok(());
}

@elrrrrrrr
Copy link
Copy Markdown
Contributor

Closing as stale: this draft is a one-off agent experiment from 2026-04-27 with no follow-up, and overlaps with sibling PRs exploring the same optimization. Reopen if revisited.

@elrrrrrrr elrrrrrrr closed this May 25, 2026
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