Skip to content

Commit 3c18d85

Browse files
authored
[ty] Add micro-benchmark for #711 (#18979)
## Summary Add a benchmark for the problematic case in astral-sh/ty#711, which will potentially be solved in #18955
1 parent e5e3d99 commit 3c18d85

File tree

1 file changed

+49
-3
lines changed
  • crates/ruff_benchmark/benches

1 file changed

+49
-3
lines changed

crates/ruff_benchmark/benches/ty.rs

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

351-
fn benchmark_many_attribute_assignments(criterion: &mut Criterion) {
351+
fn benchmark_complex_constrained_attributes_1(criterion: &mut Criterion) {
352352
setup_rayon();
353353

354-
criterion.bench_function("ty_micro[many_attribute_assignments]", |b| {
354+
criterion.bench_function("ty_micro[complex_constrained_attributes_1]", |b| {
355355
b.iter_batched_ref(
356356
|| {
357357
// 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) {
400400
});
401401
}
402402

403+
fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) {
404+
setup_rayon();
405+
406+
criterion.bench_function("ty_micro[complex_constrained_attributes_2]", |b| {
407+
b.iter_batched_ref(
408+
|| {
409+
// This is is similar to the case above, but now the attributes are actually defined.
410+
// https://github.com/astral-sh/ty/issues/711
411+
setup_micro_case(
412+
r#"
413+
class C:
414+
def f(self: "C"):
415+
self.a = ""
416+
self.b = ""
417+
418+
if isinstance(self.a, str):
419+
return
420+
421+
if isinstance(self.b, str):
422+
return
423+
if isinstance(self.b, str):
424+
return
425+
if isinstance(self.b, str):
426+
return
427+
if isinstance(self.b, str):
428+
return
429+
if isinstance(self.b, str):
430+
return
431+
if isinstance(self.b, str):
432+
return
433+
if isinstance(self.b, str):
434+
return
435+
"#,
436+
)
437+
},
438+
|case| {
439+
let Case { db, .. } = case;
440+
let result = db.check();
441+
assert_eq!(result.len(), 0);
442+
},
443+
BatchSize::SmallInput,
444+
);
445+
});
446+
}
447+
403448
struct ProjectBenchmark<'a> {
404449
project: InstalledProject<'a>,
405450
fs: MemoryFileSystem,
@@ -534,7 +579,8 @@ criterion_group!(
534579
micro,
535580
benchmark_many_string_assignments,
536581
benchmark_many_tuple_assignments,
537-
benchmark_many_attribute_assignments,
582+
benchmark_complex_constrained_attributes_1,
583+
benchmark_complex_constrained_attributes_2,
538584
);
539585
criterion_group!(project, anyio, attrs, hydra);
540586
criterion_main!(check_file, micro, project);

0 commit comments

Comments
 (0)