Skip to content
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

Reorganize leak tracker for better performance. #106

Merged
merged 54 commits into from
Aug 1, 2023

Conversation

polina-c
Copy link
Contributor

@polina-c polina-c commented Jul 27, 2023

This PR introduces notion of phase of leak tracking. Different phases may have different names and settings.

testWidgetsWithLeakTracking now:

  1. Sets settings for the concrete tests
  2. Starts leak tracking if it is not started yet
  3. Configures tearDownAll to collect leaks for all tests and the throw exception if leaks are found
  4. In case of found leaks, each leak will have the test name specified

Also this PR removes APIs that are not used in Flutter Framework.

As result, leak tracking stopped being noticeable from performance perspective.

@polina-c polina-c changed the title Perf Refactor leak tracker for better performance. Jul 27, 2023
@polina-c polina-c changed the title Refactor leak tracker for better performance. Reorganize leak tracker for better performance. Jul 27, 2023
Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass, I'll need to go through this again later today / early tomorrow.


/// For these tests `expect` for found leaks happens in flutter_test_config.dart.
void main() {
testWidgetsWithLeakTracking(test1TrackingOn, (widgetTester) async {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to have the test names here in strings instead of in variables. That way it will be easier to read what is being tested without needing to jump around.
Example: "starting phases with tracking-on"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, if we're not generating the names programmatically, we should just use string literals in testWidgets(...)

Copy link
Contributor Author

@polina-c polina-c Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to reference the test name in other places, so I need them to be variables.
I named the variables to mimic their value to make it more readable.

Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

@@ -96,6 +110,8 @@ abstract class LeakTracking {
Map<String, dynamic>? context,
}) {
assert(() {
if (phase.isPaused) return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree with the idea in principle, but most of the examples there are quite a bit more complex than these closures. The return value in these cases is boilerplate, so this just reads weird to me. I'll leave it up to you :)


/// For these tests `expect` for found leaks happens in flutter_test_config.dart.
void main() {
testWidgetsWithLeakTracking(test1TrackingOn, (widgetTester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, if we're not generating the names programmatically, we should just use string literals in testWidgets(...)

@polina-c polina-c merged commit b045c5e into dart-lang:main Aug 1, 2023
@polina-c polina-c deleted the perf branch August 1, 2023 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants