mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Remove spawn_blocking
from version map (#1966)
I previously add `spawn_blocking` to the version map construction as it had become a bottleneck (https://github.com/astral-sh/uv/pull/1163/files#diff-704ceeaedada99f90369eac535713ec82e19550bff166cd44745d7277ecae527R116). With the zero copy deserialization, this has become so fast we don't need to move it to the thread pool anymore. I've also checked `DataWithCachePolicy` but it seems to still take a significant amount of time. Span visualization: Resolving jupyter warm:  Resolving jupyter cold:   I've also updated the instrumentation a little. We don't seem cpu bound for the cold cache (top) and refresh case (bottom) from jupyter:  
This commit is contained in:
parent
c80d5c6ffb
commit
70dad51cd9
5 changed files with 62 additions and 57 deletions
|
@ -1,6 +1,4 @@
|
|||
use std::future::Future;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
@ -62,11 +60,6 @@ pub trait ResolverProvider: Send + Sync {
|
|||
pub struct DefaultResolverProvider<'a, Context: BuildContext + Send + Sync> {
|
||||
/// The [`DistributionDatabase`] used to build source distributions.
|
||||
fetcher: DistributionDatabase<'a, Context>,
|
||||
/// Allow moving the parameters to `VersionMap::from_metadata` to a different thread.
|
||||
inner: Arc<DefaultResolverProviderInner>,
|
||||
}
|
||||
|
||||
pub struct DefaultResolverProviderInner {
|
||||
/// The [`RegistryClient`] used to query the index.
|
||||
client: RegistryClient,
|
||||
/// These are the entries from `--find-links` that act as overrides for index responses.
|
||||
|
@ -77,14 +70,6 @@ pub struct DefaultResolverProviderInner {
|
|||
no_binary: NoBinary,
|
||||
}
|
||||
|
||||
impl<'a, Context: BuildContext + Send + Sync> Deref for DefaultResolverProvider<'a, Context> {
|
||||
type Target = DefaultResolverProviderInner;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.inner.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Context: BuildContext + Send + Sync> DefaultResolverProvider<'a, Context> {
|
||||
/// Reads the flat index entries and builds the provider.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
@ -99,14 +84,12 @@ impl<'a, Context: BuildContext + Send + Sync> DefaultResolverProvider<'a, Contex
|
|||
) -> Self {
|
||||
Self {
|
||||
fetcher,
|
||||
inner: Arc::new(DefaultResolverProviderInner {
|
||||
client: client.clone(),
|
||||
flat_index: flat_index.clone(),
|
||||
tags: tags.clone(),
|
||||
python_requirement,
|
||||
exclude_newer,
|
||||
no_binary: no_binary.clone(),
|
||||
}),
|
||||
client: client.clone(),
|
||||
flat_index: flat_index.clone(),
|
||||
tags: tags.clone(),
|
||||
python_requirement,
|
||||
exclude_newer,
|
||||
no_binary: no_binary.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,24 +107,16 @@ impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
|
|||
// If the "Simple API" request was successful, convert to `VersionMap` on the Tokio
|
||||
// threadpool, since it can be slow.
|
||||
match result {
|
||||
Ok((index, metadata)) => {
|
||||
let self_send = self.inner.clone();
|
||||
let package_name_owned = package_name.clone();
|
||||
Ok(tokio::task::spawn_blocking(move || {
|
||||
VersionsResponse::Found(VersionMap::from_metadata(
|
||||
metadata,
|
||||
&package_name_owned,
|
||||
&index,
|
||||
&self_send.tags,
|
||||
&self_send.python_requirement,
|
||||
self_send.exclude_newer.as_ref(),
|
||||
self_send.flat_index.get(&package_name_owned).cloned(),
|
||||
&self_send.no_binary,
|
||||
))
|
||||
})
|
||||
.await
|
||||
.expect("Tokio executor failed, was there a panic?"))
|
||||
}
|
||||
Ok((index, metadata)) => Ok(VersionsResponse::Found(VersionMap::from_metadata(
|
||||
metadata,
|
||||
package_name,
|
||||
&index,
|
||||
&self.tags,
|
||||
&self.python_requirement,
|
||||
self.exclude_newer.as_ref(),
|
||||
self.flat_index.get(package_name).cloned(),
|
||||
&self.no_binary,
|
||||
))),
|
||||
Err(err) => match err.into_kind() {
|
||||
uv_client::ErrorKind::PackageNotFound(_) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue