mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Optimizations plus bug fix (#541)
* Optimize `Download::and_extract`: Avoid dup monomorphization * Increase buffer size for binstall_crates_v1 to `4096 * 5` * Optimize `opts::resolve`: Avoid unnecessary `clone`s * Fix reserve in `opts::resolve`: Do not over-reserve * Rename field `opts::Options::resolver` => `resolvers` * Refactor: Extract new type `resolve::PackageInfo` - which makes `opts::resolve_inner` easier to understand - reduce number of parameters required for `download_extract_and_verify` and `collect_bin_files` - reducing size of future returned by `opts::resolve_inner` by dropping `cargo_toml::{Manifest, Package}` as early as possible since `Manifest` is 3000 Bytes large while `Package` is 600 Bytes large. * Optimize `fetchers::Data`: Use `CompactString` for field name & version since they are usually small enough to fit in inlined version of `CompactString`. * Optimize `gh_crate_meta`: Avoid unnecessary allocation in `RepositoryHost::get_default_pkg_url_template`. * Refacator: Use `Itertools::cartesian_product` in `apply_filenames_to_paths` * Optimize `ops::resolve`: Avoid unnecessary `clone` & reduce future size by calling `fetcher.target_meta()` to obtain final metadata after downloaded and extracted the binaries. * Optimize `ops::resolve`: Avoid unnecessary allocation in `download_extract_and_verify`: Replace `Itertools::join` with `Itertools::format` to avoid allocating the string. * Fix disabling cargo-install fallback * Simplify `BinFile::from_product`: Takes `&str` instead of `&Product` since we only need `product.name` * Rename `BinFile::from_product` => `BinFile::new` * Refactor: Create newtype `ops::resolve::Bin` so that we don't need to `unwrap()` on `Product::name` and reduce memory usage. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
bb1f51a739
commit
325cb5cc19
9 changed files with 220 additions and 160 deletions
|
@ -122,22 +122,30 @@ impl Download {
|
|||
path: impl AsRef<Path>,
|
||||
cancellation_future: CancellationFuture,
|
||||
) -> Result<(), DownloadError> {
|
||||
let stream = self.client.get_stream(self.url).await?;
|
||||
async fn inner(
|
||||
this: Download,
|
||||
fmt: PkgFmt,
|
||||
path: &Path,
|
||||
cancellation_future: CancellationFuture,
|
||||
) -> Result<(), DownloadError> {
|
||||
let stream = this.client.get_stream(this.url).await?;
|
||||
|
||||
let path = path.as_ref();
|
||||
debug!("Downloading and extracting to: '{}'", path.display());
|
||||
debug!("Downloading and extracting to: '{}'", path.display());
|
||||
|
||||
match fmt.decompose() {
|
||||
PkgFmtDecomposed::Tar(fmt) => {
|
||||
extract_tar_based_stream(stream, path, fmt, cancellation_future).await?
|
||||
match fmt.decompose() {
|
||||
PkgFmtDecomposed::Tar(fmt) => {
|
||||
extract_tar_based_stream(stream, path, fmt, cancellation_future).await?
|
||||
}
|
||||
PkgFmtDecomposed::Bin => extract_bin(stream, path, cancellation_future).await?,
|
||||
PkgFmtDecomposed::Zip => extract_zip(stream, path, cancellation_future).await?,
|
||||
}
|
||||
PkgFmtDecomposed::Bin => extract_bin(stream, path, cancellation_future).await?,
|
||||
PkgFmtDecomposed::Zip => extract_zip(stream, path, cancellation_future).await?,
|
||||
|
||||
debug!("Download OK, extracted to: '{}'", path.display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
debug!("Download OK, extracted to: '{}'", path.display());
|
||||
|
||||
Ok(())
|
||||
inner(self, fmt, path.as_ref(), cancellation_future).await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue