-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Create class MemoryAllocations. #110230
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
Create class MemoryAllocations. #110230
Conversation
dnfield
left a comment
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.
I'm not quite clear on how this will be used or why it belongs in the framework at this point.
goderbauer
left a comment
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.
It's kinda difficult reviewing this skeleton without docs filled in and seeing how this would be used by other parts of the framework.
| object: this, | ||
| )); | ||
| } | ||
| _creationDispatched = true; |
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.
Why is the inherited implementation from ChangeNotifier not enough? Also, it is odd that this is reaching out to a private in ChangeNotifier. Does that mean, I couldn't implement my own ValueNotifier-like class based on ChangeNotifier outside of the framework?
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.
Yes, the implementation is not super-elegant. However, as there is no constructor in ChangeNotifier (because it is used as mixin), I did not find a better way.
You can implement ValueNotifier-like class based on ChangeNotifier though. It will dispatch the events if only a listener is added.
| @override | ||
| void addListener(VoidCallback listener) { | ||
| assert(ChangeNotifier.debugAssertNotDisposed(this)); | ||
| if (!_creationDispatched) { |
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.
One thought that occurred to me: In release builds that ship to customers you probably want this entire code tree-shaken out. That's currently no possible?
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.
Thank you for bringing it. Introduced kFlutterMemoryAllocationsEnabled and verified tree-shaking happens (see screen shot in description)
| assert(ChangeNotifier.debugAssertNotDisposed(this)); | ||
| if (!_creationDispatched) { | ||
| if (MemoryAllocations.instance.hasListeners) { | ||
| MemoryAllocations.instance.dispatchObjectEvent(ObjectCreated( |
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.
I am not sure how these events will be consumed, but will it not be confusing if an object creation notification is received somewhat randomly long after the object has been created?
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.
Yes, it is not perfect, but I do not see other way to inform about ChangeNotifier creation.
|
|
||
| /// List of the Flutter Framework and SDK libraries with instrumented | ||
| /// classes. | ||
| class FlutterLibraries { |
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.
Does this have to be public API?
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.
reomoved
| try { | ||
| listeners[i]?.call(objectEvent); | ||
| } catch (exception, stack) { | ||
| final String type = objectEvent.object.runtimeType.toString(); |
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.
There should be a no_runtimeType_toString lint on this line, no?
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.
nope
And if i remove the type, I get lint about return type
| return; | ||
| } | ||
|
|
||
| if (_activeDispatchLoops > 0) { |
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.
For my own understanding, why is the removal/notification logic so different from ChangeNotifier? I wish we could just reuse that logic instead of reinventing everything.
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.
ChangeNotifier is different, because it is not-singletone and is optimized for often adding/removing listeners.
One of comments in ChangeNotifier is 'The list holding the listeners is not growable for performances reasons.'.
We are ok with growable list for MemoryAllocations, because it is singletone.
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.
We still care about performance for event dispatching, as the number of events can be huge.
goderbauer
left a comment
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.
LGTM
|
SkiaPerf is reporting regressions in some microbenchmarks on this change: Does the flag to disable this feature need to be passed in more places? |
|
Following up. |
|
Regression is triggered by: Command: |
|
From offline conversation:
@polina-c is going to follow up with a patch to remove the |
|
fix: #111615 |
|
(to get this link i opened the regression link and scrolled right by pressing 'd') |
Design: go/dart-leaktracker-productization
Peer PR in engine: flutter/engine#35274
Verified memory_allocations.dart is not included into release build if the flag
--dart-define=flutter.memory_allocations=trueis not passed: