From 18c0b97d9d57f7778a1501fe2698034374bc1db4 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 22 Aug 2022 20:45:13 -0700 Subject: [PATCH] cli: remove `jj bench` commands I haven't used these in a long time. Not including it reduces the binary size from 16.8 MB to 15.1 MiB. --- Cargo.toml | 1 - src/commands.rs | 142 +----------------------------------------------- 2 files changed, 1 insertion(+), 142 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4de97d22e..f154fb280 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,6 @@ clap = { version = "4.0.9", features = ["derive", "deprecated"] } clap_complete = "4.0.2" clap_mangen = "0.2.2" config = { version = "0.13.2", default-features = false, features = ["toml"] } -criterion = "0.4.0" dirs = "4.0.0" git2 = "0.15.0" hex = "0.4.3" diff --git a/src/commands.rs b/src/commands.rs index 668026aea..b8319f877 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -19,12 +19,10 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::ops::Range; use std::path::{Path, PathBuf}; use std::sync::Arc; -use std::time::Instant; use std::{fs, io}; use chrono::{FixedOffset, TimeZone, Utc}; use clap::{ArgGroup, ArgMatches, CommandFactory, FromArgMatches, Subcommand}; -use criterion::Criterion; use itertools::Itertools; use jujutsu_lib::backend::{BackendError, CommitId, Timestamp, TreeValue}; use jujutsu_lib::commit::Commit; @@ -33,7 +31,7 @@ use jujutsu_lib::dag_walk::topo_order_reverse; use jujutsu_lib::diff::{Diff, DiffHunk}; use jujutsu_lib::files::DiffLine; use jujutsu_lib::git::{GitFetchError, GitRefUpdate}; -use jujutsu_lib::index::{HexPrefix, IndexEntry}; +use jujutsu_lib::index::IndexEntry; use jujutsu_lib::matchers::{EverythingMatcher, Matcher}; use jujutsu_lib::op_store::{RefTarget, WorkspaceId}; use jujutsu_lib::operation::Operation; @@ -117,8 +115,6 @@ enum Commands { #[command(subcommand)] Git(GitCommands), #[command(subcommand)] - Bench(BenchCommands), - #[command(subcommand)] Debug(DebugCommands), } @@ -921,47 +917,6 @@ struct GitImportArgs {} #[derive(clap::Args, Clone, Debug)] struct GitExportArgs {} -/// Commands for benchmarking internal operations -#[derive(Subcommand, Clone, Debug)] -enum BenchCommands { - #[command(name = "commonancestors")] - CommonAncestors(BenchCommonAncestorsArgs), - #[command(name = "isancestor")] - IsAncestor(BenchIsAncestorArgs), - #[command(name = "walkrevs")] - WalkRevs(BenchWalkRevsArgs), - #[command(name = "resolveprefix")] - ResolvePrefix(BenchResolvePrefixArgs), -} - -/// Find the common ancestor(s) of a set of commits -#[derive(clap::Args, Clone, Debug)] -struct BenchCommonAncestorsArgs { - revision1: String, - revision2: String, -} - -/// Checks if the first commit is an ancestor of the second commit -#[derive(clap::Args, Clone, Debug)] -struct BenchIsAncestorArgs { - ancestor: String, - descendant: String, -} - -/// Walk revisions that are ancestors of the second argument but not ancestors -/// of the first -#[derive(clap::Args, Clone, Debug)] -struct BenchWalkRevsArgs { - unwanted: String, - wanted: String, -} - -/// Resolve a commit ID prefix -#[derive(clap::Args, Clone, Debug)] -struct BenchResolvePrefixArgs { - prefix: String, -} - /// Low-level commands not intended for users #[derive(Subcommand, Clone, Debug)] #[command(hide = true)] @@ -3586,100 +3541,6 @@ fn cmd_debug( Ok(()) } -fn run_bench(ui: &mut Ui, id: &str, mut routine: R) -> io::Result<()> -where - R: (FnMut() -> O) + Copy, - O: Debug, -{ - let mut criterion = Criterion::default(); - let before = Instant::now(); - let result = routine(); - let after = Instant::now(); - writeln!( - ui, - "First run took {:?} and produced: {:?}", - after.duration_since(before), - result - )?; - criterion.bench_function(id, |bencher: &mut criterion::Bencher| { - bencher.iter(routine); - }); - Ok(()) -} - -fn cmd_bench( - ui: &mut Ui, - command: &CommandHelper, - subcommand: &BenchCommands, -) -> Result<(), CommandError> { - match subcommand { - BenchCommands::CommonAncestors(command_matches) => { - let workspace_command = command.workspace_helper(ui)?; - let commit1 = workspace_command.resolve_single_rev(&command_matches.revision1)?; - let commit2 = workspace_command.resolve_single_rev(&command_matches.revision2)?; - let index = workspace_command.repo().index(); - let routine = - || index.common_ancestors(&[commit1.id().clone()], &[commit2.id().clone()]); - run_bench( - ui, - &format!( - "commonancestors-{}-{}", - &command_matches.revision1, &command_matches.revision2 - ), - routine, - )?; - } - BenchCommands::IsAncestor(command_matches) => { - let workspace_command = command.workspace_helper(ui)?; - let ancestor_commit = - workspace_command.resolve_single_rev(&command_matches.ancestor)?; - let descendant_commit = - workspace_command.resolve_single_rev(&command_matches.descendant)?; - let index = workspace_command.repo().index(); - let routine = || index.is_ancestor(ancestor_commit.id(), descendant_commit.id()); - run_bench( - ui, - &format!( - "isancestor-{}-{}", - &command_matches.ancestor, &command_matches.descendant - ), - routine, - )?; - } - BenchCommands::WalkRevs(command_matches) => { - let workspace_command = command.workspace_helper(ui)?; - let unwanted_commit = - workspace_command.resolve_single_rev(&command_matches.unwanted)?; - let wanted_commit = workspace_command.resolve_single_rev(&command_matches.wanted)?; - let index = workspace_command.repo().index(); - let routine = || { - index - .walk_revs( - &[wanted_commit.id().clone()], - &[unwanted_commit.id().clone()], - ) - .count() - }; - run_bench( - ui, - &format!( - "walkrevs-{}-{}", - &command_matches.unwanted, &command_matches.wanted - ), - routine, - )?; - } - BenchCommands::ResolvePrefix(command_matches) => { - let workspace_command = command.workspace_helper(ui)?; - let prefix = HexPrefix::new(command_matches.prefix.clone()).unwrap(); - let index = workspace_command.repo().index(); - let routine = || index.resolve_prefix(&prefix); - run_bench(ui, &format!("resolveprefix-{}", prefix.hex()), routine)?; - } - } - Ok(()) -} - fn format_timestamp(timestamp: &Timestamp) -> String { let utc = Utc .timestamp( @@ -4567,7 +4428,6 @@ pub fn run_command( Commands::Workspace(sub_args) => cmd_workspace(ui, command_helper, sub_args), Commands::Sparse(sub_args) => cmd_sparse(ui, command_helper, sub_args), Commands::Git(sub_args) => cmd_git(ui, command_helper, sub_args), - Commands::Bench(sub_args) => cmd_bench(ui, command_helper, sub_args), Commands::Debug(sub_args) => cmd_debug(ui, command_helper, sub_args), } }