Bug 160238 - [Coordinated Graphics] Improve scheduling of tasks between threads in CoordinatedGraphicsScene
Summary: [Coordinated Graphics] Improve scheduling of tasks between threads in Coordin...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2016-07-27 04:11 PDT by Carlos Garcia Campos
Modified: 2016-07-27 08:59 PDT (History)
3 users (show)

See Also:


Attachments
Patch (19.76 KB, patch)
2016-07-27 04:18 PDT, Carlos Garcia Campos
mcatanzaro: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2016-07-27 04:11:50 PDT
Avoid scheduling tasks to the main thread if the scene is detached. Do not take references when not actually sending tasks to another threads. Use Function instead of std::function on dispatch methods. Remove purgeBackingStores that is actually never called.
Comment 1 Carlos Garcia Campos 2016-07-27 04:18:14 PDT
Created attachment 284684 [details]
Patch
Comment 2 Michael Catanzaro 2016-07-27 06:44:22 PDT
Comment on attachment 284684 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=284684&action=review

Questions

> Source/WebKit2/ChangeLog:12
> +         - Use Function instead of std::function on dispatch methods.

Why, just to use our thing instead of the standard one? Is there an advantage to WTF::Function?

> Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:44
> +    RunLoop::main().dispatch([protectedThis = makeRef(*this), function = WTFMove(function)] {

Why is this correct? We don't use |this| inside the lambda, so why the need to keep it alive? If the ref is really needed then it should be handled inside |function|, right?

> Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:56
> +    m_clientRunLoop.dispatch([protectedThis = makeRef(*this), function = WTFMove(function)] {

Ditto.

> Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:158
> +    dispatchOnClientRunLoop([this] {

Why no protector?

> Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:622
> +    dispatchOnMainThread([this] {

Ditto.

> Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:689
> +    dispatchOnMainThread([this, layerID, offset] {

Ditto.
Comment 3 Carlos Garcia Campos 2016-07-27 06:51:53 PDT
(In reply to comment #2)
> Comment on attachment 284684 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=284684&action=review
> 
> Questions
> 
> > Source/WebKit2/ChangeLog:12
> > +         - Use Function instead of std::function on dispatch methods.
> 
> Why, just to use our thing instead of the standard one? Is there an
> advantage to WTF::Function?

This is WTF::Function.

> > Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:44
> > +    RunLoop::main().dispatch([protectedThis = makeRef(*this), function = WTFMove(function)] {
> 
> Why is this correct? We don't use |this| inside the lambda, so why the need
> to keep it alive? If the ref is really needed then it should be handled
> inside |function|, right?

Just to ensure the scene is alive, that's why it's called protectedThis. Before this patch all caller do that themselves, and in some cases unnecessarily, because we only need it when scheduling to another thread. Now it's done here to simplify the callers.

> > Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:56
> > +    m_clientRunLoop.dispatch([protectedThis = makeRef(*this), function = WTFMove(function)] {
> 
> Ditto.

Ditto.

> > Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:158
> > +    dispatchOnClientRunLoop([this] {
> 
> Why no protector?

Because dispatchOnClientRunLoop is protecting this only when actually needed.

> > Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:622
> > +    dispatchOnMainThread([this] {
> 
> Ditto.
> 
> > Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:689
> > +    dispatchOnMainThread([this, layerID, offset] {
> 
> Ditto.

Ditto.
Comment 4 Michael Catanzaro 2016-07-27 08:22:04 PDT
(In reply to comment #3) 
> This is WTF::Function.

Why is WTF::Function preferred to std::function?
Comment 5 Carlos Garcia Campos 2016-07-27 08:44:30 PDT
(In reply to comment #4)
> (In reply to comment #3) 
> > This is WTF::Function.
> 
> Why is WTF::Function preferred to std::function?

WTF::Function is non-copyable, so it's safer to use between threads and allows to capture things like Ref<>
Comment 6 Carlos Garcia Campos 2016-07-27 08:59:30 PDT
Committed r203776: <http://trac.webkit.org/changeset/203776>