mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 12:10:02 +00:00
Minor refactor and optimization (#543)
* Avoid potential panicking in `args::parse` by using `Vec::get` instead of indexing * Refactor: Simplify `opts::{resolve, install}` API Many parameters can be shared and put into `opts::Options` intead and that would also avoid a few `Arc<Path>`. * Optimize `get_install_path`: Avoid cloning `install_path` * Optimize `LazyJobserverClient`: Un`Arc` & remove `Clone` impl to avoid additional boxing * Optimize `find_version`: Avoid cloning `semver::Version` * Optimize `GhCrateMeta::launch_baseline_find_tasks` return `impl Iterator<Item = impl Future<Output = ...>>` instead of `impl Iterator<Item = AutoAbortJoinHandle<...>>` to avoid unnecessary spawning. Each task spawned has to be boxed and then polled by tokio runtime. They might also be moved. While they increase parallelism, spawning these futures does not justify the costs because: - Each `Future` only calls `remote_exists` - Each `remote_exists` call send requests to the same domain, which is likely to share the same http2 connection. Since the conn is shared anyway, spawning does not speedup anything but merely add communication overhead. - Plus the tokio runtime spawning cost * Optimize `install_crates`: Destruct `Args` before any `.await` point to reduce size of the future * Refactor `logging`: Replace param `arg` with `log_level` & `json_output` to avoid dep on `Args` * Add dep strum & strum_macros to crates/bin * Derive `strum_macros::EnumCount` for `Strategy` * Optimize strategies parsing in `install_crates` * Fix panic in `install_crates` when `Compile` is not the last strategy specified * Optimize: Take `Vec<Self>` instead of slice in `CrateName::dedup` * Refactor: Extract new fn `compute_resolvers` * Refactor: Extract new fn `compute_paths_and_load_manifests` * Refactor: Extract new fn `filter_out_installed_crates` * Reorder `install_crates`: Only run target detection if args are valid and there are some crates to be installed. * Optimize `filter_out_installed_crates`: Avoid allocation by returning an `Iterator` * Fix user_agent of `remote::Client`: Let user specify it * Refactor: Replace `UIThread` with `ui::confirm` which is much simpler. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
325cb5cc19
commit
50b6e62164
16 changed files with 325 additions and 348 deletions
|
@ -13,8 +13,6 @@ use tracing_core::{identify_callsite, metadata::Kind, subscriber::Subscriber};
|
|||
use tracing_log::AsTrace;
|
||||
use tracing_subscriber::{filter::targets::Targets, fmt::fmt, layer::SubscriberExt};
|
||||
|
||||
use crate::args::Args;
|
||||
|
||||
// Shamelessly taken from tracing-log
|
||||
|
||||
struct Fields {
|
||||
|
@ -131,9 +129,9 @@ impl Log for Logger {
|
|||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
pub fn logging(args: &Args) {
|
||||
pub fn logging(log_level: LevelFilter, json_output: bool) {
|
||||
// Calculate log_level
|
||||
let log_level = min(args.log_level, STATIC_MAX_LEVEL);
|
||||
let log_level = min(log_level, STATIC_MAX_LEVEL);
|
||||
|
||||
let allowed_targets =
|
||||
(log_level != LevelFilter::Trace).then_some(["binstalk", "cargo_binstall"]);
|
||||
|
@ -145,7 +143,7 @@ pub fn logging(args: &Args) {
|
|||
let log_level = log_level.as_trace();
|
||||
let subscriber_builder = fmt().with_max_level(log_level);
|
||||
|
||||
let subscriber: Box<dyn Subscriber + Send + Sync> = if args.json_output {
|
||||
let subscriber: Box<dyn Subscriber + Send + Sync> = if json_output {
|
||||
Box::new(subscriber_builder.json().finish())
|
||||
} else {
|
||||
// Disable time, target, file, line_num, thread name/ids to make the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue