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

perf(search): benchmark smart sort #2202

Merged
merged 1 commit into from
Jun 26, 2024
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
51 changes: 51 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/atuin-history/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ tracing = "0.1"
uuid = { workspace = true }
unicode-segmentation = "1.11.0"
sysinfo = "0.30.7"

[dev-dependencies]
tracing-tree = "0.3"
divan = "0.1.14"
rand = { workspace = true }

[[bench]]
name = "smart_sort"
harness = false
35 changes: 35 additions & 0 deletions crates/atuin-history/benches/smart_sort.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use atuin_client::history::History;
use atuin_history::sort::sort;

use rand::Rng;

fn main() {
// Run registered benchmarks.
divan::main();
}

// Smart sort usually runs on 200 entries, test on a few sizes
#[divan::bench(args=[100, 200, 400, 800, 1600, 10000])]
fn smart_sort(lines: usize) {
// benchmark a few different sizes of "history"
// first we need to generate some history. This will use a whole bunch of memory, sorry
let mut rng = rand::thread_rng();
let now = time::OffsetDateTime::now_utc().unix_timestamp();

let possible_commands = ["echo", "ls", "cd", "grep", "atuin", "curl"];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do with making this a bit more comprehensive

let mut commands = Vec::<History>::with_capacity(lines);

for _ in 0..lines {
let command = possible_commands[rng.gen_range(0..possible_commands.len())];

let command = History::import()
.command(command)
.timestamp(time::OffsetDateTime::from_unix_timestamp(rng.gen_range(0..now)).unwrap())
.build()
.into();

commands.push(command);
}

let _ = sort("curl", commands);
}
1 change: 1 addition & 0 deletions crates/atuin-history/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod sort;
pub mod stats;
1 change: 0 additions & 1 deletion crates/atuin/src/command/client/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod engines;
mod history_list;
mod inspector;
mod interactive;
mod sort;

pub use duration::format_duration_into;

Expand Down
6 changes: 4 additions & 2 deletions crates/atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use super::{
cursor::Cursor,
engines::{SearchEngine, SearchState},
history_list::{HistoryList, ListState, PREFIX_LENGTH},
sort,
};

use crate::{command::client::search::engines, VERSION};
Expand Down Expand Up @@ -96,7 +95,10 @@ impl State {
self.results_len = results.len();

if smart_sort {
Ok(sort::sort(self.search.input.as_str(), results))
Ok(atuin_history::sort::sort(
self.search.input.as_str(),
results,
))
} else {
Ok(results)
}
Expand Down
Loading