mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Add regression-benchmark for attribute-assignment hang (#18957)
## Summary
Adds a new micro-benchmark as a regression test for
https://github.com/astral-sh/ty/issues/627.
## Test Plan
Ran the benchmark on the parent commit of
89d915a1e3
,
and verified that it took > 1s, while it takes ~10 ms after the fix.
This commit is contained in:
parent
86fd9b634e
commit
d04e63a6d9
1 changed files with 53 additions and 0 deletions
|
@ -348,6 +348,58 @@ fn benchmark_many_tuple_assignments(criterion: &mut Criterion) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn benchmark_many_attribute_assignments(criterion: &mut Criterion) {
|
||||||
|
setup_rayon();
|
||||||
|
|
||||||
|
criterion.bench_function("ty_micro[many_attribute_assignments]", |b| {
|
||||||
|
b.iter_batched_ref(
|
||||||
|
|| {
|
||||||
|
// This is a regression benchmark for https://github.com/astral-sh/ty/issues/627.
|
||||||
|
// Before this was fixed, the following sample would take >1s to type check.
|
||||||
|
setup_micro_case(
|
||||||
|
r#"
|
||||||
|
class C:
|
||||||
|
def f(self: "C"):
|
||||||
|
if isinstance(self.a, str):
|
||||||
|
return
|
||||||
|
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
if isinstance(self.b, str):
|
||||||
|
return
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|case| {
|
||||||
|
let Case { db, .. } = case;
|
||||||
|
let result = db.check();
|
||||||
|
assert!(!result.is_empty());
|
||||||
|
},
|
||||||
|
BatchSize::SmallInput,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
struct ProjectBenchmark<'a> {
|
struct ProjectBenchmark<'a> {
|
||||||
project: InstalledProject<'a>,
|
project: InstalledProject<'a>,
|
||||||
fs: MemoryFileSystem,
|
fs: MemoryFileSystem,
|
||||||
|
@ -483,6 +535,7 @@ criterion_group!(
|
||||||
micro,
|
micro,
|
||||||
benchmark_many_string_assignments,
|
benchmark_many_string_assignments,
|
||||||
benchmark_many_tuple_assignments,
|
benchmark_many_tuple_assignments,
|
||||||
|
benchmark_many_attribute_assignments,
|
||||||
);
|
);
|
||||||
criterion_group!(project, anyio, attrs, hydra);
|
criterion_group!(project, anyio, attrs, hydra);
|
||||||
criterion_main!(check_file, micro, project);
|
criterion_main!(check_file, micro, project);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue