diff --git a/crates/pm/src/service/binary.rs b/crates/pm/src/service/binary.rs index c6f95cb45e..7ef28fb2af 100644 --- a/crates/pm/src/service/binary.rs +++ b/crates/pm/src/service/binary.rs @@ -233,6 +233,11 @@ async fn handle_cypress( } pub async fn update_package_binary(dir: &Path, name: &str) -> Result<()> { + // npm.org has no China mirror layer — skip alongside `get_envs`. + if should_skip_binary_mirror() { + return Ok(()); + } + let config = load_config().await?; let mirrors = config["mirrors"]["china"] diff --git a/crates/pm/src/util/cloner.rs b/crates/pm/src/util/cloner.rs index 76c6029702..e15c69b95d 100644 --- a/crates/pm/src/util/cloner.rs +++ b/crates/pm/src/util/cloner.rs @@ -65,6 +65,13 @@ pub async fn clone_package_once( target_path: &Path, ) -> Result<()> { let key = cache_key(target_path); + + // Skip the param clones + future construction when the pipeline + // (or a sibling task) already cloned this target. + if CLONE_CACHE.is_done(&key) { + return Ok(()); + } + let err_label = format!("{name}@{version}"); let name = name.to_string(); let version = version.to_string(); @@ -326,8 +333,12 @@ async fn validate_directory(src: &Path, dst: &Path) -> Result { pub async fn find_real_src>(src: P) -> Option { let mut read_dir = fs::read_dir(src.as_ref()).await.ok()?; while let Some(entry) = read_dir.next_entry().await.ok()? { - if let Ok(metadata) = entry.metadata().await - && metadata.is_dir() + // `file_type()` reads `d_type` from the cached readdir result on + // ext4/btrfs/xfs (no extra syscall); `metadata()` always issues + // an `lstat`. Saves ~3–5 stats per call × N packages on the + // cold install hot path. + if let Ok(file_type) = entry.file_type().await + && file_type.is_dir() && let Some(name) = entry.path().file_name() && name.to_string_lossy() != ".utoo_built" { diff --git a/crates/pm/src/util/downloader.rs b/crates/pm/src/util/downloader.rs index 76526eedda..ee7bf3c838 100644 --- a/crates/pm/src/util/downloader.rs +++ b/crates/pm/src/util/downloader.rs @@ -149,6 +149,12 @@ pub async fn resolve_cache_path(name: &str, version: &str, tarball_url: &str) -> /// For git-resolved packages, use [`resolve_cache_path`] instead. pub async fn download_to_cache(name: &str, version: &str, tarball_url: &str) -> Option { let key = format!("{}@{}", name, version); + + // Skip the param clones + future construction on cache hit. + if let Some(cache_path) = DOWNLOAD_CACHE.get(&key) { + return Some((*cache_path).clone()); + } + let cache_dir = get_cache_dir(); let name = name.to_string(); let version = version.to_string(); @@ -167,7 +173,9 @@ pub async fn download_to_cache(name: &str, version: &str, tarball_url: &str) -> return Some(cache_path); } - // Download (semaphore controlled) + // Download (semaphore controlled). Permit held through extract + // — A/B-revert experiment to test if early permit release is + // the source of utoo p0 σ being ~2× baseline. let semaphore = DOWNLOAD_SEMAPHORE .get_or_init(|| Semaphore::new(get_manifests_concurrency_limit_sync())); let _permit = semaphore.acquire().await.ok()?; diff --git a/crates/ruborist/src/util/oncemap.rs b/crates/ruborist/src/util/oncemap.rs index 40c4aeee20..7bb1e710cc 100644 --- a/crates/ruborist/src/util/oncemap.rs +++ b/crates/ruborist/src/util/oncemap.rs @@ -118,6 +118,21 @@ where } } + /// Sync presence probe — `Done` only, single `DashMap::get`. + /// Returns `false` for unknown / `Waiting` slots. + pub fn is_done(&self, key: &K) -> bool { + self.get(key).is_some() + } + + /// Sync fetch of a completed value, single `DashMap::get`. + /// Returns `None` for unknown / `Waiting` slots. + pub fn get(&self, key: &K) -> Option> { + self.map.get(key).and_then(|e| match e.value() { + Value::Done(v) => Some(Arc::clone(v)), + Value::Waiting(_) => None, + }) + } + /// Wait for a key to complete. /// /// - If the key exists and is Done, returns immediately.