lotabout.skim/benches/read_and_match.rs
LoricAndre bb6c03f377
feat: reduce binary size by removing uncommon image formats and color_eyre (#1118)
* Shrink binary: trim image decoders and swap color-eyre for eyre

Two dependency changes that cut the default `sk` binary from 13.6 MiB to
8.55 MiB (-5.06 MiB, -37%) with no loss of core functionality:

- image: build the `image` crate with only the common decoders (png,
  jpeg, gif, webp) instead of its full default format set, and drop
  ratatui-image's `image-defaults`. This removes AVIF encoding (ravif,
  avif-serialize), OpenEXR (exr), TIFF, QOI and other decoders that are
  irrelevant to terminal image previews. Previewing those formats now
  falls back to the normal command preview.

- error handling: replace color-eyre with plain eyre. color-eyre only
  provided colored panic/error backtraces; skim used none of its
  Section/Help extension APIs. This drops the backtrace/gimli/addr2line/
  color-spantrace stack. `color_eyre::install()` is no longer needed.

Tests, benches and examples are migrated from color_eyre to eyre so the
crate is fully removed from the dependency graph.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQtxeCS4gM7dumghqmNgST

* chore: fmt

* docs: ARCHITECTURE.md

* chore(flake): add cargo-bloat

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-17 17:29:43 +00:00

132 lines
4.4 KiB
Rust

#![allow(missing_docs, clippy::pedantic)]
use criterion::{Criterion, criterion_group, criterion_main};
use eyre::{Ok, Result};
use skim::prelude::*;
async fn wait_until_done(mut opts: SkimOptions) -> Result<SkimOutput> {
opts.cmd = Some(String::from("cat benches/fixtures/10M.txt"));
let mut skim = Skim::init(opts, None)?;
skim.start();
skim.init_tui()?;
skim.enter().await?;
while !skim.tick().await? {
if skim.reader_done() && skim.matcher_stopped() {
skim.event_sender().send(Event::Action(Action::Accept(None))).await?;
}
}
Ok(skim.output())
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("default", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt)
.iter(async || wait_until_done(SkimOptions::default()).await);
});
c.bench_function("query", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt)
.iter(async || wait_until_done(SkimOptionsBuilder::default().query("test").build().unwrap()).await);
});
#[cfg(feature = "frizbee")]
c.bench_function("query_frizbee", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt).iter(async || {
wait_until_done(
SkimOptionsBuilder::default()
.query("test")
.algorithm(FuzzyAlgorithm::Frizbee)
.no_typos(true)
.build()
.unwrap(),
)
.await
});
});
c.bench_function("query_ari", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt).iter(async || {
wait_until_done(
SkimOptionsBuilder::default()
.query("test")
.algorithm(FuzzyAlgorithm::Arinae)
.no_typos(true)
.build()
.unwrap(),
)
.await
});
});
#[cfg(feature = "frizbee")]
c.bench_function("query_frizbee_typos", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt).iter(async || {
wait_until_done(
SkimOptionsBuilder::default()
.query("test")
.algorithm(FuzzyAlgorithm::Frizbee)
.build()
.unwrap(),
)
.await
});
});
c.bench_function("query_ari_typos", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt).iter(async || {
wait_until_done(
SkimOptionsBuilder::default()
.query("test")
.algorithm(FuzzyAlgorithm::Arinae)
.build()
.unwrap(),
)
.await
});
});
c.bench_function("typing", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt).iter(async || {
let mut skim = Skim::init(SkimOptionsBuilder::default().cmd("cat bench_data.txt").build()?, None)?;
skim.start();
skim.init_tui()?;
skim.enter().await?;
let s = skim.event_sender();
let mut sent = false;
let mut done_since = 0;
let mut done = false;
while !skim.tick().await? {
if skim.reader_done() && skim.matcher_stopped() {
if done {
done_since += 1;
} else {
done_since = 1;
}
if sent && done_since > 50 {
s.send(Event::Action(Action::Accept(None))).await?;
} else if !sent {
s.send(Event::Action(Action::AddChar('t'))).await?;
s.send(Event::Action(Action::AddChar('e'))).await?;
s.send(Event::Action(Action::AddChar('s'))).await?;
s.send(Event::Action(Action::AddChar('t'))).await?;
sent = true;
}
done = true;
} else {
done = false;
}
}
Ok(skim.output())
});
});
}
criterion_group!(
name = benches;
config = Criterion::default().sample_size(10);
targets = criterion_benchmark
);
criterion_main!(benches);