Skip to content

Commit 1eddff6

Browse files
committed
More projects
1 parent 7cdfea4 commit 1eddff6

File tree

4 files changed

+211
-114
lines changed

4 files changed

+211
-114
lines changed

crates/ruff_benchmark/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ harness = false
4242
required-features = ["instrumented"]
4343

4444
[[bench]]
45-
name = "ty_project"
45+
name = "ty_walltime"
4646
harness = false
4747
required-features = ["walltime"]
4848

@@ -73,7 +73,7 @@ codspeed = ["codspeed-criterion-compat"]
7373
# Enables benchmark that should only run with codspeed's walltime runner.
7474
# May disable benchmarks that only run on instrument runners.
7575
instrumented = []
76-
walltime = []
76+
walltime = ["ruff_db/os"]
7777

7878
[target.'cfg(target_os = "windows")'.dev-dependencies]
7979
mimalloc = { workspace = true }

crates/ruff_benchmark/benches/ty.rs

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::disallowed_names)]
22
use ruff_benchmark::criterion;
3+
use ruff_benchmark::real_world_projects::RealWorldProject;
34

45
use std::ops::Range;
56

@@ -11,10 +12,10 @@ use ruff_benchmark::TestFile;
1112
use ruff_db::diagnostic::{Diagnostic, DiagnosticId, Severity};
1213
use ruff_db::files::{File, system_path_to_file};
1314
use ruff_db::source::source_text;
14-
use ruff_db::system::{MemoryFileSystem, SystemPath, SystemPathBuf, TestSystem};
15+
use ruff_db::system::{InMemorySystem, MemoryFileSystem, SystemPath, SystemPathBuf, TestSystem};
1516
use ruff_python_ast::PythonVersion;
1617
use ty_project::metadata::options::{EnvironmentOptions, Options};
17-
use ty_project::metadata::value::RangedValue;
18+
use ty_project::metadata::value::{RangedValue, RelativePathBuf};
1819
use ty_project::watch::{ChangeEvent, ChangedKind};
1920
use ty_project::{Db, ProjectDatabase, ProjectMetadata};
2021

@@ -347,10 +348,141 @@ fn benchmark_many_tuple_assignments(criterion: &mut Criterion) {
347348
});
348349
}
349350

351+
#[track_caller]
352+
fn bench_project(project: RealWorldProject, criterion: &mut Criterion, max_diagnostics: usize) {
353+
fn setup(
354+
metadata: &ProjectMetadata,
355+
system: &TestSystem,
356+
check_paths: &[&SystemPath],
357+
) -> ProjectDatabase {
358+
// Create new database instance and collect files for this instance
359+
let mut db = ProjectDatabase::new(metadata.clone(), system.clone()).unwrap();
360+
361+
db.project().set_included_paths(
362+
&mut db,
363+
check_paths.iter().map(|path| path.to_path_buf()).collect(),
364+
);
365+
db
366+
}
367+
368+
fn check_project(db: &mut ProjectDatabase, max_diagnostics: usize) {
369+
let result = db.check();
370+
// Don't assert specific diagnostic count for real-world projects
371+
// as they may have legitimate type issues
372+
let diagnostics = result.len();
373+
374+
assert!(
375+
diagnostics > 1 && diagnostics <= max_diagnostics,
376+
"Expected between {} and {} diagnostics but got {}",
377+
1,
378+
max_diagnostics,
379+
diagnostics
380+
);
381+
}
382+
383+
setup_rayon();
384+
385+
let setup_project = project.setup().expect("Failed to setup project");
386+
387+
let fs = setup_project
388+
.copy_to_memory_fs()
389+
.expect("Failed to copy project to memory fs");
390+
let system = TestSystem::new(InMemorySystem::from_memory_fs(fs));
391+
392+
let src_root = SystemPath::new("/");
393+
let mut metadata = ProjectMetadata::discover(src_root, &system).unwrap();
394+
395+
metadata.apply_options(Options {
396+
environment: Some(EnvironmentOptions {
397+
python_version: Some(RangedValue::cli(setup_project.config.python_version)),
398+
python: (!setup_project.config().dependencies.is_empty())
399+
.then_some(RelativePathBuf::cli(SystemPath::new(".venv"))),
400+
..EnvironmentOptions::default()
401+
}),
402+
..Options::default()
403+
});
404+
405+
let check_paths = setup_project.check_paths();
406+
407+
criterion.bench_function(&format!("project[{}]", setup_project.config.name), |b| {
408+
b.iter_batched_ref(
409+
|| setup(&metadata, &system, check_paths),
410+
|db| check_project(db, max_diagnostics),
411+
BatchSize::SmallInput,
412+
);
413+
});
414+
}
415+
416+
fn pydantic(criterion: &mut Criterion) {
417+
// Setup the colour-science project (expensive, done once)
418+
let project = RealWorldProject {
419+
name: "pydantic",
420+
repository: "https://github.com/pydantic/pydantic",
421+
commit: "0c4a22b64b23dfad27387750cf07487efc45eb05",
422+
paths: &[SystemPath::new("pydantic")],
423+
dependencies: &[
424+
"annotated-types",
425+
"pydantic-core",
426+
"typing-extensions",
427+
"typing-inspection",
428+
],
429+
max_dep_date: "2025-06-17",
430+
python_version: PythonVersion::PY39,
431+
};
432+
433+
bench_project(project, criterion, 1000);
434+
}
435+
436+
fn hydra(criterion: &mut Criterion) {
437+
// Setup the colour-science project (expensive, done once)
438+
let project = RealWorldProject {
439+
name: "hydra-zen",
440+
repository: "https://github.com/mit-ll-responsible-ai/hydra-zen",
441+
commit: "dd2b50a9614c6f8c46c5866f283c8f7e7a960aa8",
442+
paths: &[SystemPath::new("src")],
443+
dependencies: &["pydantic", "beartype", "hydra-core"],
444+
max_dep_date: "2025-06-17",
445+
python_version: PythonVersion::PY313,
446+
};
447+
448+
bench_project(project, criterion, 100);
449+
}
450+
451+
fn attrs(criterion: &mut Criterion) {
452+
// Setup the colour-science project (expensive, done once)
453+
let project = RealWorldProject {
454+
name: "attrs",
455+
repository: "https://github.com/python-attrs/attrs",
456+
commit: "a6ae894aad9bc09edc7cdad8c416898784ceec9b",
457+
paths: &[SystemPath::new("src")],
458+
dependencies: &[],
459+
max_dep_date: "2025-06-17",
460+
python_version: PythonVersion::PY313,
461+
};
462+
463+
bench_project(project, criterion, 100);
464+
}
465+
466+
fn anyio(criterion: &mut Criterion) {
467+
// Setup the colour-science project (expensive, done once)
468+
let project = RealWorldProject {
469+
name: "anyio",
470+
repository: "https://github.com/agronholm/anyio",
471+
commit: "561d81270a12f7c6bbafb5bc5fad99a2a13f96be",
472+
paths: &[SystemPath::new("src")],
473+
dependencies: &[],
474+
max_dep_date: "2025-06-17",
475+
python_version: PythonVersion::PY313,
476+
};
477+
478+
bench_project(project, criterion, 100);
479+
}
480+
350481
criterion_group!(check_file, benchmark_cold, benchmark_incremental);
351482
criterion_group!(
352483
micro,
353484
benchmark_many_string_assignments,
354485
benchmark_many_tuple_assignments,
355486
);
356-
criterion_main!(check_file, micro);
487+
criterion_group!(project, anyio, attrs, hydra);
488+
criterion_main!(check_file, micro, project);

0 commit comments

Comments
 (0)