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

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented May 29, 2019

Ameliorates flutter/flutter#31138

This is a work around which should eventually be removed. Users have reported that since splitting the UI and IO threads when platform views are enabled, it is easy to lock up the entire application when typing while an animation (e.g. the blinking cursor or a spinner) is running. This issue most reliably reproduces in profile or release mode, but can be noticed less significantly in debug mode. This change must be reverted if we go to dynamic thread merging and unmerging, as we don't currently handle restoring the pipeline depth when the threads split (only when the animator is constructed).

This patch makes it harder to stall the platform thread on the GPU when the threads are merged by reducing parallelization in rendering/rasterization. In a single threaded configuration, the pipeline never gets a chance to get above 1, whereas when the UI thread is split out it gets a chance to schedule additional frames while the rasterizer is going. In this case, the merged GPU/Platform thread (which is really just the Platform thread), tries to

The problem can be seen in flutter tracing as in the linked bug - a glClear call ends up taking much longer than normal, which blocks the platform thread for one or more frames. In Xcode tracing, this can be observed as a 1 second pause with "Thread blocked while waiting for next drawable" (the large purple boxes in the screen shot below):

image

I have three ideas for other, larger scale improvements that may fix this:

  1. Move to Metal, which would allow us some more levers to play with around the GPU fencing and allow us to have more control over which layer(s) are accessing the GPU at a given instant.
  2. Minimize the amount of time the GPU and Platform threads are merged. This problem is either difficult or impossible to manifest when the threads are split.
  3. Avoid mergint the threads at all, and let the GPU thread interrupt the platform thread in this configuration (e.g. let it hand the platform thread a task to execute immediately rather than at the end of its queue).

@amirh
Copy link
Contributor

amirh commented May 29, 2019

To add some more context:
We've been spending a lot of time investigating the issue, which we still do not understand. Some speculations we have are around a potential bug a in the GL driver, or around synchronization issues in the GL driver code which we do not have access to.

As we have reached a dead end with the investigation, we've decide to try and reduce exposure to the issue, as a first step by reducing the pipeline depth to 1(which makes it equivalent to the single threaded case as in that case the UI thread never has a chance to submit a frame while the GPU thread is rasterizing). Another potential way to reduce exposure to the problem will be a thread merging strategy that keeps the threads unmerged for as long as possible(once dynamic thread configuraiton lands). We also believe it's likely that we will stop seeing the issue once we move to metal.

For anyone coming back to investigate this, to make it easier to reproduce you should set the pipeline depth to 2, make sure you're running with just the gpu and platform threads merged, have some animation ongoing, and type really fast in a Flutter TextField.

Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

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

LGTM (left a comment adding more context as for why we're landing this)

@dnfield
Copy link
Contributor Author

dnfield commented May 29, 2019

(Updated PR description to add more context)

@dnfield
Copy link
Contributor Author

dnfield commented May 29, 2019

Only other note here - part of the goal of this patch is to have something that is attainable for the next beta to help people who are currently broken. The suggested improvements here are believed to take more time than the next beta.

@dnfield dnfield merged commit fa9b5bd into flutter:master May 30, 2019
@dnfield dnfield deleted the pipeline_depth branch May 30, 2019 02:45
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 30, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request May 30, 2019
flutter/engine@4c4c0f8...fa9b5bd

git log 4c4c0f8..fa9b5bd --no-merges --oneline
fa9b5bd Reduce pipeline depth when GPU and Platform are same thread (flutter/engine#9132)
d479412 Change the virtual display size restriction to warning (flutter/engine#9110)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff ([email protected]), and stop
the roller if necessary.
huqiuser pushed a commit to huqiuser/engine that referenced this pull request Jun 12, 2019
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.

3 participants