Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Only parallel load tools that have a configured version. #697

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

## Unreleased

#### 🚀 Updates

- Updated parallel tool loading to only loads tools that have a configured version, instead of loading all tools that proto is aware of (like built-in tools). Should see better performance for commands that require loading multiple tools.

#### ⚙️ Internal

- Updated Rust to v1.84.
Expand Down
5 changes: 1 addition & 4 deletions crates/cli/src/commands/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::Serialize;
use starbase::AppResult;
use starbase_shell::{Hook, ShellType, Statement};
use starbase_utils::json;
use std::collections::HashSet;
use std::env;
use std::path::{Path, PathBuf};
use tokio::task::JoinSet;
Expand Down Expand Up @@ -82,9 +81,7 @@ pub async fn activate(session: ProtoSession, args: ActivateArgs) -> AppResult {
let config = session.env.load_config()?;

// Load necessary tools so that we can extract info
let tools = session
.load_tools_with_filters(HashSet::from_iter(config.versions.keys()))
.await?;
let tools = session.load_tools().await?;
let mut info = ActivateInfo::default();
let mut set = JoinSet::<miette::Result<ActivateItem>>::new();

Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ pub async fn install_one(session: ProtoSession, args: InstallArgs, id: Id) -> Ap
async fn install_all(session: ProtoSession, args: InstallArgs) -> AppResult {
debug!("Loading all tools");

let tools = session.load_tools().await?;
// We need all tools so we can attempt to detect a version
let tools = session.load_all_tools().await?;

debug!("Detecting tool versions to install");

Expand Down
8 changes: 7 additions & 1 deletion crates/cli/src/commands/plugin/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub async fn list(session: ProtoSession, args: ListPluginsArgs) -> AppResult {

let mut tools = session
.load_tools_with_options(LoadToolOptions {
ids: FxHashSet::from_iter(args.ids.clone()),
ids: FxHashSet::from_iter(if args.ids.is_empty() {
// Use plugins instead of versions since we want to
// list all plugins currently in use, even built-ins
global_config.plugins.keys().cloned().collect::<Vec<_>>()
} else {
args.ids.clone()
}),
inherit_local: true,
inherit_remote: true,
..Default::default()
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ async fn find_versions_from_ecosystem(
) -> AppResult {
let mut set = JoinSet::new();

for tool in session.load_tools().await? {
// We need all tools so we can attempt to detect a version
for tool in session.load_all_tools().await? {
let env = Arc::clone(&session.env);

set.spawn(async move {
Expand Down
20 changes: 19 additions & 1 deletion crates/cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,18 @@ impl ProtoSession {
#[tracing::instrument(name = "load_tools", skip(self))]
pub async fn load_tools_with_options(
&self,
options: LoadToolOptions,
mut options: LoadToolOptions,
) -> miette::Result<Vec<ToolRecord>> {
let config = self.env.load_config()?;

// If no filter IDs provided, inherit the IDs from the current
// config for every tool that has a version. Otherwise, we'll
// load all tools, even built-ins, when the user isn't using them.
// This causes quite a performance hit.
if options.ids.is_empty() {
options.ids.extend(config.versions.keys().cloned());
}

// Download the schema plugin before loading plugins.
// We must do this here, otherwise when multiple schema
// based tools are installed in parallel, they will
Expand Down Expand Up @@ -183,6 +191,16 @@ impl ProtoSession {
Ok(records)
}

pub async fn load_all_tools(&self) -> miette::Result<Vec<ToolRecord>> {
let config = self.load_config()?;

let mut set = FxHashSet::default();
set.extend(config.versions.keys().collect::<Vec<_>>());
set.extend(config.plugins.keys().collect::<Vec<_>>());

self.load_tools_with_filters(set).await
}

pub async fn load_proto_tool(&self) -> miette::Result<Tool> {
load_tool_from_locator(
Id::new(PROTO_PLUGIN_KEY)?,
Expand Down
Loading