diff --git a/crates/ruff_benchmark/benches/ty.rs b/crates/ruff_benchmark/benches/ty.rs index a917c4a028..14763127c4 100644 --- a/crates/ruff_benchmark/benches/ty.rs +++ b/crates/ruff_benchmark/benches/ty.rs @@ -348,10 +348,10 @@ fn benchmark_many_tuple_assignments(criterion: &mut Criterion) { }); } -fn benchmark_many_attribute_assignments(criterion: &mut Criterion) { +fn benchmark_complex_constrained_attributes_1(criterion: &mut Criterion) { setup_rayon(); - criterion.bench_function("ty_micro[many_attribute_assignments]", |b| { + criterion.bench_function("ty_micro[complex_constrained_attributes_1]", |b| { b.iter_batched_ref( || { // This is a regression benchmark for https://github.com/astral-sh/ty/issues/627. @@ -400,6 +400,51 @@ fn benchmark_many_attribute_assignments(criterion: &mut Criterion) { }); } +fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { + setup_rayon(); + + criterion.bench_function("ty_micro[complex_constrained_attributes_2]", |b| { + b.iter_batched_ref( + || { + // This is is similar to the case above, but now the attributes are actually defined. + // https://github.com/astral-sh/ty/issues/711 + setup_micro_case( + r#" + class C: + def f(self: "C"): + self.a = "" + self.b = "" + + 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 + "#, + ) + }, + |case| { + let Case { db, .. } = case; + let result = db.check(); + assert_eq!(result.len(), 0); + }, + BatchSize::SmallInput, + ); + }); +} + struct ProjectBenchmark<'a> { project: InstalledProject<'a>, fs: MemoryFileSystem, @@ -534,7 +579,8 @@ criterion_group!( micro, benchmark_many_string_assignments, benchmark_many_tuple_assignments, - benchmark_many_attribute_assignments, + benchmark_complex_constrained_attributes_1, + benchmark_complex_constrained_attributes_2, ); criterion_group!(project, anyio, attrs, hydra); criterion_main!(check_file, micro, project);