-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[ty] Benchmarks for problematic implicit instance attributes cases #20133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -450,9 +450,6 @@ fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { | |
| r#" | ||
| class C: | ||
| def f(self: "C"): | ||
| self.a = "" | ||
| self.b = "" | ||
|
|
||
| if isinstance(self.a, str): | ||
| return | ||
|
|
||
|
|
@@ -466,6 +463,56 @@ fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { | |
| return | ||
| if isinstance(self.b, str): | ||
| return | ||
| if isinstance(self.b, str): | ||
| return | ||
| if isinstance(self.b, str): | ||
| return | ||
|
Comment on lines
+466
to
+469
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We reduced this so much that it wasn't actually showing a problematic runtime anymore. So I added two more clauses. |
||
|
|
||
| self.a = "" | ||
| self.b = "" | ||
| "#, | ||
| ) | ||
| }, | ||
| |case| { | ||
| let Case { db, .. } = case; | ||
| let result = db.check(); | ||
| assert_eq!(result.len(), 0); | ||
| }, | ||
| BatchSize::SmallInput, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| fn benchmark_complex_constrained_attributes_3(criterion: &mut Criterion) { | ||
| setup_rayon(); | ||
|
|
||
| criterion.bench_function("ty_micro[complex_constrained_attributes_3]", |b| { | ||
| b.iter_batched_ref( | ||
| || { | ||
| // This is a regression test for https://github.com/astral-sh/ty/issues/758 | ||
| setup_micro_case( | ||
| r#" | ||
| class GridOut: | ||
| def __init__(self: "GridOut") -> None: | ||
| self._buffer = b"" | ||
|
|
||
| def _read_size_or_line(self: "GridOut", size: int = -1): | ||
| if size > self._position: | ||
| size = self._position | ||
| pass | ||
| if size == 0: | ||
| return bytes() | ||
|
|
||
| while size > 0: | ||
| if self._buffer: | ||
| buf = self._buffer | ||
| self._buffer = b"" | ||
| else: | ||
| buf = b"" | ||
|
|
||
| if len(buf) > size: | ||
| self._buffer = buf | ||
| self._position -= len(self._buffer) | ||
| "#, | ||
| ) | ||
| }, | ||
|
|
@@ -668,6 +715,7 @@ criterion_group!( | |
| benchmark_tuple_implicit_instance_attributes, | ||
| benchmark_complex_constrained_attributes_1, | ||
| benchmark_complex_constrained_attributes_2, | ||
| benchmark_complex_constrained_attributes_3, | ||
| benchmark_many_enum_members, | ||
| ); | ||
| criterion_group!(project, anyio, attrs, hydra, datetype); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently something changed here, because previously it was able to reproduce this with the attributes at the beginning of the method. Now it only seems to reproduce if they are defined at the end, after all
returns.