Skip to content

Commit d04e63a

Browse files
authored
[ty] Add regression-benchmark for attribute-assignment hang (#18957)
## Summary Adds a new micro-benchmark as a regression test for astral-sh/ty#627. ## Test Plan Ran the benchmark on the parent commit of 89d915a, and verified that it took > 1s, while it takes ~10 ms after the fix.
1 parent 86fd9b6 commit d04e63a

File tree

1 file changed

+53
-0
lines changed
  • crates/ruff_benchmark/benches

1 file changed

+53
-0
lines changed

crates/ruff_benchmark/benches/ty.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,58 @@ fn benchmark_many_tuple_assignments(criterion: &mut Criterion) {
348348
});
349349
}
350350

351+
fn benchmark_many_attribute_assignments(criterion: &mut Criterion) {
352+
setup_rayon();
353+
354+
criterion.bench_function("ty_micro[many_attribute_assignments]", |b| {
355+
b.iter_batched_ref(
356+
|| {
357+
// This is a regression benchmark for https://github.com/astral-sh/ty/issues/627.
358+
// Before this was fixed, the following sample would take >1s to type check.
359+
setup_micro_case(
360+
r#"
361+
class C:
362+
def f(self: "C"):
363+
if isinstance(self.a, str):
364+
return
365+
366+
if isinstance(self.b, str):
367+
return
368+
if isinstance(self.b, str):
369+
return
370+
if isinstance(self.b, str):
371+
return
372+
if isinstance(self.b, str):
373+
return
374+
if isinstance(self.b, str):
375+
return
376+
if isinstance(self.b, str):
377+
return
378+
if isinstance(self.b, str):
379+
return
380+
if isinstance(self.b, str):
381+
return
382+
if isinstance(self.b, str):
383+
return
384+
if isinstance(self.b, str):
385+
return
386+
if isinstance(self.b, str):
387+
return
388+
if isinstance(self.b, str):
389+
return
390+
"#,
391+
)
392+
},
393+
|case| {
394+
let Case { db, .. } = case;
395+
let result = db.check();
396+
assert!(!result.is_empty());
397+
},
398+
BatchSize::SmallInput,
399+
);
400+
});
401+
}
402+
351403
struct ProjectBenchmark<'a> {
352404
project: InstalledProject<'a>,
353405
fs: MemoryFileSystem,
@@ -483,6 +535,7 @@ criterion_group!(
483535
micro,
484536
benchmark_many_string_assignments,
485537
benchmark_many_tuple_assignments,
538+
benchmark_many_attribute_assignments,
486539
);
487540
criterion_group!(project, anyio, attrs, hydra);
488541
criterion_main!(check_file, micro, project);

0 commit comments

Comments
 (0)