Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@liyuqian
Copy link
Contributor

Without this, developers have to override onReportTimings to listen for FrameTiming.
That can potentially break previous onReportTimings listeners if they forget to call
the 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
onReportTimings usages.

Once that's done, we can then propose the breaking change of removing the deprecated
onReportTimings.

Copy link
Contributor

@devoncarew devoncarew left a 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

typedef FrameCallback = void Function(Duration duration);

/// Signature for [Window.onReportTimings].
/// Signature for [Window._onReportTimings].
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

/// See also:
///
/// * [FrameTiming], the data event of this stream
Stream<FrameTiming> get frameTimingStream {
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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);
}

Copy link
Member

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.

Copy link
Contributor Author

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.

typedef FrameCallback = void Function(Duration duration);

/// Signature for [Window.onReportTimings].
/// Signature for [Window._onReportTimings].
Copy link
Member

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.

///
/// 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
Copy link
Member

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"

Copy link
Contributor Author

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
Copy link
Member

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"?

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor

@devoncarew devoncarew left a 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

@liyuqian
Copy link
Contributor Author

@goderbauer : any more suggestions? Otherwise I'll merge today.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@liyuqian liyuqian merged commit e97ed36 into flutter:master Aug 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2019
iskakaushik pushed a commit to flutter/flutter that referenced this pull request Aug 19, 2019
* 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)
iskakaushik pushed a commit to iskakaushik/flutter that referenced this pull request Aug 19, 2019
Filed: flutter#38838
to track these usages.

This was introduced by: flutter/engine#11041
iskakaushik pushed a commit to iskakaushik/engine that referenced this pull request Aug 19, 2019
iskakaushik added a commit to flutter/flutter that referenced this pull request Aug 19, 2019
liyuqian added a commit to flutter/flutter that referenced this pull request Aug 28, 2019
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.
@Hixie
Copy link
Contributor

Hixie commented Sep 1, 2019

We try pretty hard not to use streams in Flutter, they have all kinds of problems. What was wrong with the old API?

@dnfield
Copy link
Contributor

dnfield commented Sep 3, 2019

@Hixie do you think we could get a section in the style guide on when and when not to use streams?

liyuqian added a commit that referenced this pull request Sep 5, 2019
This reverts commit e97ed36.

Reason for revert: Stream is considered a bad API: #11041 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants