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

Fix wrong VSYNC event #36775

Merged
merged 5 commits into from
Oct 29, 2022
Merged

Conversation

fzyzcjy
Copy link
Contributor

@fzyzcjy fzyzcjy commented Oct 15, 2022

Firstly, we know VSYNC event in timeline is special - chrome://tracing tool will show "zebra" colors (gray and white) at every VSYNC. Therefore, it is critical to let this event have correct timing, otherwise every user is doing reasoning with the wrong vsync time.

In the image below, the "a" shows the new VSYNC with this PR, while the "b" shows the old VSYNC interval before this PR. As we can see, the left side of "a" and "b" does not coincide. In other words, before this PR (where we have "b" as the VSYNC and there is no "a"), we consider the wrong time as the vsync time.

The cause is quite simple: Before this PR, the left edge of "VSYNC" event is (for example) the call time of VsyncWaiterAndroid::OnVsyncFromJava. However, there exist "frame delay" (e.g. frameDelayNanos argument in OnVsyncFromJava), so the real vsync time should minus that delay.

As a side remark, in the image below the difference is not very much, but in real scenarios, I have seen once in a while it has large differences. Then you know, the visualization goes wild, and it took me some time before I realized, it is not a bug in code anywhere, but a bug of the VSYNC event time.

image

Close #113475

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@fzyzcjy fzyzcjy marked this pull request as ready for review October 15, 2022 02:19
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@chinmaygarde
Copy link
Member

cc @dnfield

@dnfield dnfield requested a review from iskakaushik October 27, 2022 20:29
@@ -109,6 +109,17 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
return;
}

// The event named "VSYNC" is special in `chrome://tracing` tool - it will
Copy link
Contributor

Choose a reason for hiding this comment

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

Why here?

This means the event won't get emitted on vsyncs where there's no callback, right?

I think making this more accurate is a good idea, but probably should fire unconditionally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right! I have not thought about this problem before. Let me change it (probably within hours)

@dnfield
Copy link
Contributor

dnfield commented Oct 27, 2022

@iskakaushik can you provide a secondary review here?

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM, would appreciate a review from @iskakaushik too

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

@iskakaushik iskakaushik added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 29, 2022
@auto-submit auto-submit bot merged commit 9ccaa33 into flutter:main Oct 29, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2022
dnfield added a commit that referenced this pull request Nov 14, 2022
auto-submit bot pushed a commit that referenced this pull request Nov 14, 2022
schwa423 pushed a commit to schwa423/engine that referenced this pull request Nov 16, 2022
schwa423 pushed a commit to schwa423/engine that referenced this pull request Nov 16, 2022
@fzyzcjy fzyzcjy mentioned this pull request Nov 23, 2022
8 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App needs tests platform-android platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants