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

Start animator paused #29007

Merged
merged 2 commits into from
Oct 4, 2021
Merged

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Oct 4, 2021

Starts the animator in a paused state, and only starts it once we get a request to schedule frame and we have a surface to render to.

This avoids the animator doing unnecessary work during application startup, and in particular avoids it potentially signaling that we have idle time for a GC when we haven't even rendered a frame yet.

Part of flutter/flutter#91209

@@ -73,6 +73,9 @@ TEST_F(ShellTest, VSyncTargetTime) {
fml::TaskRunner::RunNowOrPostTask(shell->GetTaskRunners().GetUITaskRunner(),
[engine = shell->GetEngine()]() {
if (engine) {
// Engine needs a surface for frames to
// be scheduled.
engine->OnOutputSurfaceCreated();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a slight change in behavior here that broke this test - before, the test never created a surface so it never actually scheduled frames and the call below this was a no-op. Now, there's an implicit call to RequestFrame(false) in this call. @iskakaushik

@@ -106,15 +106,15 @@ class Animator final {

std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder_;
uint64_t frame_request_number_ = 1;
int64_t dart_frame_deadline_;
int64_t dart_frame_deadline_ = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Can we convert this to use time points in FML instead? I can't tell what unit the deadline is supposed to be in.

I know this wasn't the point of this patch but moving the initializers to the header seems to be a drive-by change. So, perhaps you are interested in cleaning this little but up as well. Fine if you'd rather not.

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 - would you mind taking a look to make sure what I did looks reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dnfield dnfield added waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. and removed waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. labels Oct 4, 2021
@dnfield
Copy link
Contributor Author

dnfield commented Oct 4, 2021

This still has a problem - because of the logic in

if (paused_ && !dimension_change_pending_) {
this still ends up awaiting vsync initially.

@dnfield
Copy link
Contributor Author

dnfield commented Oct 4, 2021

I am wrong. I was looking at a stale trace file.

This patch substantially improves internal customer's startup times.

Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

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

LGTM

@dnfield
Copy link
Contributor Author

dnfield commented Oct 4, 2021

There is still something not quite right about this patch. Going to mark it as a draft until I figure out exactly what.

@dnfield dnfield marked this pull request as draft October 4, 2021 21:19
@dnfield
Copy link
Contributor Author

dnfield commented Oct 4, 2021

Ok. The problem is that we have multiple places calling ScheduleFrame in the engine. In particular when the GPU surface gets created it triggers a ScheduleFrame that succeeds in starting the animator even though the application is not actually trying to render any frames yet.

I think this patch makes sense to land. I will look at separately landing a patch to make the engine avoid responding to NotifyIdle before a frame has rendered.

@dnfield dnfield marked this pull request as ready for review October 4, 2021 22:13
@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Oct 4, 2021
@fluttergithubbot fluttergithubbot merged commit 009d1f6 into flutter:master Oct 4, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 4, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 5, 2021
dnfield added a commit to dnfield/engine that referenced this pull request Oct 6, 2021
@dnfield dnfield deleted the animator_idle branch October 20, 2021 21:54
yx-mike added a commit to yx-mike/engine that referenced this pull request Jan 12, 2022
Do not call Animator::Delegate::OnAnimatorNotifyIdle until at least one frame has been rendered. (flutter#29015)
yx-mike added a commit to yx-mike/engine that referenced this pull request Jan 18, 2022
Do not call Animator::Delegate::OnAnimatorNotifyIdle until at least one frame has been rendered. (flutter#29015)

flutter/flutter#91209
yx-mike added a commit to yx-mike/engine that referenced this pull request May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants