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

Allow embedders to schedule a callback on all engine managed threads. #15980

Merged
merged 3 commits into from
Jan 27, 2020

Conversation

chinmaygarde
Copy link
Member

@chinmaygarde chinmaygarde commented Jan 24, 2020

FlutterEnginePostCallbackOnAllNativeThreads schedule a callback to be run on
all engine managed threads. The engine will attempt to service this callback the
next time the message loops for each managed thread is idle. Since the engine
manages the entire lifecycle of multiple threads, there is no opportunity for
the embedders to finely tune the priorities of threads directly, or, perform
other thread specific configuration (for example, setting thread names for
tracing). This callback gives embedders a chance to affect such tuning.

Fixes flutter/flutter#49551
Fixes b/143774406
Fixes b/148278215
Fixes b/148278931

@chinmaygarde
Copy link
Member Author

cc @dnicoara

/// @param[in] user_data A baton passed by the engine to the callback. This
/// baton is not interpreted by the engine in any way.
///
/// @return The flutter export.
Copy link
Member

Choose a reason for hiding this comment

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

Change this to "The result of the call"

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -1747,3 +1746,27 @@ FlutterEngineResult FlutterEngineNotifyLowMemoryWarning(
kInternalInconsistency,
"Could not dispatch the low memory notification message.");
}

FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads(
Copy link
Member

Choose a reason for hiding this comment

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

Question -- I didn't look through the two bugs immediately before reviewing but what's the rationale for posting to all threads and having the user potentially do something conditionally on the type param in the closure rather than having this take a thread-type and posting only to the specified task runner? Is the use-case such that you want to post on all or none?

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see -- so we can provide some guarantee of synchronicity, looks like.

Copy link
Member Author

Choose a reason for hiding this comment

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

The use case requires posting to all threads. But, I can see your approach as being viable as well. Posting to specific threads repeatedly is not a use case that we want to handle. This is supposed to be called once very early on in engine lifecycle.

Copy link
Member

Choose a reason for hiding this comment

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

Should we be warning people not to attempt to do any cross-thread latching in the closures they pass in?

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM.

@chinmaygarde
Copy link
Member Author

hmm, I just realized you cannot post a callback from a callback. I’ll make that safe and test it before committing this.

@dnicoara
Copy link
Contributor

Wondering, would this be sufficient to cover corner cases? Would it be possible for the embedder to call FlutterEnginePostCallbackOnAllNativeThreads before all the threads are created? With respect to worker threads, would it be possible for new worker threads to be spawned at arbitrary points in time?

@chinmaygarde
Copy link
Member Author

Would it be possible for the embedder to call FlutterEnginePostCallbackOnAllNativeThreads before all the threads are created?

No. If you have an engine ref, this is guaranteed to work.

With respect to worker threads, would it be possible for new worker threads to be spawned at arbitrary points in time?

The number of worker threads are constant at this time. If/when this changes, the engine can hold onto the callback till the engine instance is collected. Maybe I should document that the callback may be executed a long time into the future and the embedder should not associate any handles with the baton with the expectation that all callbacks will be made in a timely manner?

`FlutterEnginePostCallbackOnAllNativeThreads` schedule a callback to be run on
all engine managed threads. The engine will attempt to service this callback the
next time the message loops for each managed thread is idle. Since the engine
manages the entire lifecycle of multiple threads, there is no opportunity for
the embedders to finely tune the priorities of threads directly, or, perform
other thread specific configuration (for example, setting thread names for
tracing). This callback gives embedders a chance to affect such tuning.

Fixes b/143774406
Fixes b/148278215
Fixes b/148278931
@chinmaygarde
Copy link
Member Author

I have patched and tested the re-entrancy issue.

@chinmaygarde
Copy link
Member Author

The Windows presubmit failure is MSVC "fatal error C1001: An internal error has occurred in the compiler.". Will try to simplify the statement.

@dnicoara
Copy link
Contributor

Awesome, thank you for quelling my concerns!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 29, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 29, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 29, 2020
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jan 29, 2020
flutter/engine@c4229bf...ec32966

git log c4229bf..ec32966 --first-parent --oneline
2020-01-28 [email protected] Revert "Always make gpu thread different from platform thread regardless of platform view (#16068)" (flutter/engine#16161)
2020-01-28 [email protected] Roll fuchsia/sdk/core/mac-amd64 from gNitp... to 5fMtM... (flutter/engine#16153)
2020-01-28 [email protected] Revert "Disable setting a library tag handler." (flutter/engine#16157)
2020-01-28 [email protected] Always make gpu thread different from platform thread regardless of platform view (flutter/engine#16068)
2020-01-28 [email protected] Add test to ensure that concurrent message loops have at least one workers. (flutter/engine#16074)
2020-01-28 [email protected] Revert breaking PRs (flutter/engine#16148)
2020-01-28 [email protected] Roll fuchsia/sdk/core/linux-amd64 from 8Ns10... to 2rLoq... (flutter/engine#15971)
2020-01-28 [email protected] Gets the DPI for all awareness mode and older Windows versions (flutter/engine#15951)
2020-01-28 [email protected] Hold a mutex when updating all CanPostTaskToAllNativeThreads::Captures members. (flutter/engine#16085)
2020-01-28 [email protected] Disable setting a library tag handler. (flutter/engine#16086)
2020-01-28 [email protected] Web PargraphStyle TextHeightBehavior integration (flutter/engine#16075)
2020-01-28 [email protected] Fix flake by making thread ID tracking in CanPostTaskToAllNativeThreads thread safe. (flutter/engine#16081)
2020-01-28 [email protected] Remove buggy assertion in EmbedderTest::CanPostTaskToAllNativeThreads. (flutter/engine#16071)
2020-01-27 [email protected] Remove tonic/platform. (flutter/engine#16062)
2020-01-27 [email protected] Allow embedders to schedule a callback on all engine managed threads. (flutter/engine#15980)
2020-01-27 [email protected] Engine/LibTxt/dart:ui impl of TextHeightBehavior (flutter/engine#15087)
2020-01-27 [email protected] Roll src/third_party/skia f1b2b42613cb..9c1d30dd163e (8 commits) (flutter/engine#16060)
2020-01-27 [email protected] Remove stale recipe changelog. (flutter/engine#15985)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
NoamDev pushed a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
…flutter#15980)

`FlutterEnginePostCallbackOnAllNativeThreads` schedule a callback to be run on
all engine managed threads. The engine will attempt to service this callback the
next time the message loops for each managed thread is idle. Since the engine
manages the entire lifecycle of multiple threads, there is no opportunity for
the embedders to finely tune the priorities of threads directly, or, perform
other thread specific configuration (for example, setting thread names for
tracing). This callback gives embedders a chance to affect such tuning.

Fixes flutter/flutter#49551
Fixes b/143774406
Fixes b/148278215
Fixes b/148278931
NoamDev added a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
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.

Performance of <elided application> scrolling is < 30FPS P10
5 participants