-
Notifications
You must be signed in to change notification settings - Fork 6k
Add a BroadcastStream to FrameTiming #11041
Conversation
devoncarew
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.
My main comment (also in-line) is that we may want to change the name from:
Stream<FrameTiming> get frameTimingStream
to
Stream<FrameTiming> get frameTimings
lib/ui/window.dart
Outdated
| typedef FrameCallback = void Function(Duration duration); | ||
|
|
||
| /// Signature for [Window.onReportTimings]. | ||
| /// Signature for [Window._onReportTimings]. |
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'd have this continue point to onReportTimings. The TimingsCallback can be made private at the same time that onReportTimings is.
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.
+1 We shouldn't be referencing private members in a doc comment. The doc comment should include that this way of doing it is deprecated and link to the new way.
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.
Ok, I'll add ignore: deprecated usage... then. I previously changed onReportTiming to _onReportTimings mainly to silence the analyzer warnings.
lib/ui/window.dart
Outdated
| /// See also: | ||
| /// | ||
| /// * [FrameTiming], the data event of this stream | ||
| Stream<FrameTiming> get frameTimingStream { |
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.
You might instead call this frameTimings; I don't think we need the return type (Stream) in the name.
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.
Done.
|
|
||
| void _onFrameTimingListen() { | ||
| _internalSetOnReportTimings((List<FrameTiming> timings) { | ||
| timings.forEach(_frameTimingBroadcastController.add); |
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.
Is it more efficient to call timings.forEach(_frameTimingBroadcastController.add), or:
for (FrameTiming timing in timings) {
_frameTimingBroadcastController.add(timing);
}
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 believe forEach is ok here since we are passing in a method directly and do not allocate a closure.
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.
If I write a for ( in ) loop, the analyzer will complain... It forces me to write forEach.
lib/ui/window.dart
Outdated
| typedef FrameCallback = void Function(Duration duration); | ||
|
|
||
| /// Signature for [Window.onReportTimings]. | ||
| /// Signature for [Window._onReportTimings]. |
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.
+1 We shouldn't be referencing private members in a doc comment. The doc comment should include that this way of doing it is deprecated and link to the new way.
lib/ui/window.dart
Outdated
| /// | ||
| /// If no one is listening to this stream, no additional work will be done. | ||
| /// Otherwise, Flutter spends less than 0.1ms every 1 second to report the | ||
| /// timings (measured on iPhone6S). The 0.1ms is about 0.6% of 16ms (frame |
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.
uber-nit: I believe the official spelling is "iPhone 6s"
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.
Done.
| /// [FrameTiming.buildDuration] and [FrameTiming.rasterDuration]), or high | ||
| /// latencies (through [FrameTiming.totalSpan]). | ||
| /// | ||
| /// Unlike [Timeline], the timing information here is available in the release |
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.
drop the "the" before "release", "profile" and "debug"?
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.
Done.
|
|
||
| void _onFrameTimingListen() { | ||
| _internalSetOnReportTimings((List<FrameTiming> timings) { | ||
| timings.forEach(_frameTimingBroadcastController.add); |
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 believe forEach is ok here since we are passing in a method directly and do not allocate a closure.
devoncarew
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 for my part
|
@goderbauer : any more suggestions? Otherwise I'll merge today. |
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
* 19327c8 Show all license diffs (flutter/engine#11034) * e97ed36 Add a BroadcastStream to FrameTiming (flutter/engine#11041) * 21ae926 [b/139487101] Dont present session twice (flutter/engine#11222)
Filed: flutter#38838 to track these usages. This was introduced by: flutter/engine#11041
This reverts commit e97ed36.
Filed: #38838 to track these usages. This was introduced by: flutter/engine#11041
This is the continuation of flutter/engine#11041 and #38574 This is not a breaking change as we're not removing `onReportTimings` API. We're simply removing the use of it in our framework.
|
We try pretty hard not to use streams in Flutter, they have all kinds of problems. What was wrong with the old API? |
This reverts commit e97ed36.
|
@Hixie do you think we could get a section in the style guide on when and when not to use streams? |
This reverts commit e97ed36. Reason for revert: Stream is considered a bad API: #11041 (comment)
Without this, developers have to override
onReportTimingsto listen forFrameTiming.That can potentially break previous
onReportTimingslisteners if they forget to callthe old listener in their new callback.
This PR replaces the similar RP in the framework: flutter/flutter#38574
Once this PR landed, we'll have to create another framework PR to use the stream to replace
onReportTimingsusages.Once that's done, we can then propose the breaking change of removing the deprecated
onReportTimings.