2023-12-09 17:45:39 +01:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
|
|
use lazy_static::lazy_static;
|
2024-01-16 05:31:20 +01:00
|
|
|
use std::{env, rc::Rc, sync::Arc, time::Duration};
|
2024-02-13 19:23:39 +01:00
|
|
|
#[cfg(not(target_env = "msvc"))]
|
|
|
|
use tikv_jemallocator::Jemalloc;
|
2024-01-16 12:14:07 +01:00
|
|
|
use tvix_build::buildservice::DummyBuildService;
|
2024-01-20 00:49:01 +01:00
|
|
|
use tvix_eval::{builtins::impure_builtins, EvalIO};
|
2023-12-09 17:45:39 +01:00
|
|
|
use tvix_glue::{
|
2024-01-17 07:45:55 +01:00
|
|
|
builtins::{add_derivation_builtins, add_fetcher_builtins, add_import_builtins},
|
2024-02-19 16:17:13 +01:00
|
|
|
configure_nix_path,
|
|
|
|
tvix_io::TvixIO,
|
2023-12-09 17:45:39 +01:00
|
|
|
tvix_store_io::TvixStoreIO,
|
|
|
|
};
|
2024-05-10 07:59:25 +02:00
|
|
|
use tvix_store::utils::construct_services;
|
2023-12-09 17:45:39 +01:00
|
|
|
|
2024-02-13 19:23:39 +01:00
|
|
|
#[cfg(not(target_env = "msvc"))]
|
|
|
|
#[global_allocator]
|
|
|
|
static GLOBAL: Jemalloc = Jemalloc;
|
|
|
|
|
2023-12-09 17:45:39 +01:00
|
|
|
lazy_static! {
|
|
|
|
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn interpret(code: &str) {
|
|
|
|
// TODO: this is a bit annoying.
|
|
|
|
// It'd be nice if we could set this up once and then run evaluate() with a
|
|
|
|
// piece of code. b/262
|
2024-05-10 07:59:25 +02:00
|
|
|
let (blob_service, directory_service, path_info_service, nar_calculation_service) =
|
|
|
|
TOKIO_RUNTIME
|
|
|
|
.block_on(async { construct_services("memory://", "memory://", "memory://").await })
|
|
|
|
.unwrap();
|
2023-12-09 17:45:39 +01:00
|
|
|
|
2024-01-16 05:31:20 +01:00
|
|
|
// We assemble a complete store in memory.
|
|
|
|
let tvix_store_io = Rc::new(TvixStoreIO::new(
|
2024-05-10 07:59:25 +02:00
|
|
|
blob_service,
|
|
|
|
directory_service,
|
|
|
|
path_info_service.into(),
|
|
|
|
nar_calculation_service.into(),
|
2024-01-16 12:14:07 +01:00
|
|
|
Arc::<DummyBuildService>::default(),
|
2024-01-16 05:31:20 +01:00
|
|
|
TOKIO_RUNTIME.handle().clone(),
|
|
|
|
));
|
|
|
|
|
|
|
|
let mut eval = tvix_eval::Evaluation::new(
|
|
|
|
Box::new(TvixIO::new(tvix_store_io.clone() as Rc<dyn EvalIO>)) as Box<dyn EvalIO>,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
2024-01-20 00:49:01 +01:00
|
|
|
eval.builtins.extend(impure_builtins());
|
2024-02-20 17:04:33 +01:00
|
|
|
add_derivation_builtins(&mut eval, Rc::clone(&tvix_store_io));
|
|
|
|
add_fetcher_builtins(&mut eval, Rc::clone(&tvix_store_io));
|
2024-01-17 07:45:55 +01:00
|
|
|
add_import_builtins(&mut eval, tvix_store_io);
|
2023-12-09 17:45:39 +01:00
|
|
|
configure_nix_path(
|
|
|
|
&mut eval,
|
|
|
|
// The benchmark requires TVIX_BENCH_NIX_PATH to be set, so barf out
|
|
|
|
// early, rather than benchmarking tvix returning an error.
|
|
|
|
&Some(env::var("TVIX_BENCH_NIX_PATH").expect("TVIX_BENCH_NIX_PATH must be set")),
|
|
|
|
);
|
|
|
|
|
2023-12-30 21:36:48 +01:00
|
|
|
let result = eval.evaluate(code, None);
|
2023-12-09 17:45:39 +01:00
|
|
|
|
|
|
|
assert!(result.errors.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eval_nixpkgs(c: &mut Criterion) {
|
|
|
|
c.bench_function("hello outpath", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
interpret(black_box("(import <nixpkgs> {}).hello.outPath"));
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
name = benches;
|
|
|
|
config = Criterion::default().measurement_time(Duration::from_secs(30)).sample_size(10);
|
|
|
|
targets = eval_nixpkgs
|
|
|
|
);
|
|
|
|
criterion_main!(benches);
|