Bug 150590 - [GTK] Use a persistent main loop source in RunLoop glib implementation
Summary: [GTK] Use a persistent main loop source in RunLoop glib implementation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on: 150668
Blocks: 150592
  Show dependency treegraph
 
Reported: 2015-10-27 07:26 PDT by Carlos Garcia Campos
Modified: 2015-10-30 04:29 PDT (History)
4 users (show)

See Also:


Attachments
Patch (10.45 KB, patch)
2015-10-27 07:33 PDT, Carlos Garcia Campos
zan: review+
Details | Formatted Diff | Diff
Patch for landing (10.02 KB, patch)
2015-10-30 04:21 PDT, Carlos Garcia Campos
no flags 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 2015-10-27 07:26:21 PDT
It's more efficient than creating and destroying a new source for every dispatch and it simplifies the code.
Comment 1 Carlos Garcia Campos 2015-10-27 07:33:08 PDT
Created attachment 264130 [details]
Patch
Comment 2 Zan Dobersek 2015-10-28 00:54:46 PDT
Comment on attachment 264130 [details]
Patch

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

> Source/WTF/wtf/glib/RunLoopGLib.cpp:146
>      stop();
> +    g_source_destroy(m_source.get());

Is stop() still bringing anything here, given that the source is destroyed afterwards?

> Source/WTF/wtf/glib/RunLoopGLib.cpp:152
> +    gint64 current = g_get_monotonic_time();
> +    g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? current + m_fireInterval.count() : current);

I'd advise special-casing the 0-microsecond delay here, which is the most common.

> gint64 delay = 0;
> if (m_fireInterval.count())
>     delay = g_get_monotonic_time() + m_fireInterval.count()
> g_source_set_ready_time(m_source.get(), delay);

That way you avoid querying the monotonic time for most cases, and 0 delay still means 'dispatch ASAP' in GLib.

> Source/WTF/wtf/glib/RunLoopGLib.cpp:157
> +    stop();

Is stop() useful here? The source's ready time is updated afterwards anyway.
Comment 3 Carlos Garcia Campos 2015-10-29 04:47:27 PDT
(In reply to comment #2)
> Comment on attachment 264130 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=264130&action=review
> 
> > Source/WTF/wtf/glib/RunLoopGLib.cpp:146
> >      stop();
> > +    g_source_destroy(m_source.get());
> 
> Is stop() still bringing anything here, given that the source is destroyed
> afterwards?

Nope, it can be just removed.

> > Source/WTF/wtf/glib/RunLoopGLib.cpp:152
> > +    gint64 current = g_get_monotonic_time();
> > +    g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? current + m_fireInterval.count() : current);
> 
> I'd advise special-casing the 0-microsecond delay here, which is the most
> common.

Ok.

> > gint64 delay = 0;
> > if (m_fireInterval.count())
> >     delay = g_get_monotonic_time() + m_fireInterval.count()
> > g_source_set_ready_time(m_source.get(), delay);
> 
> That way you avoid querying the monotonic time for most cases, and 0 delay
> still means 'dispatch ASAP' in GLib.

Ah, right, I guess we can do this too

g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? g_get_monotonic_time() + m_fireInterval.count() : 0);

> > Source/WTF/wtf/glib/RunLoopGLib.cpp:157
> > +    stop();
> 
> Is stop() useful here? The source's ready time is updated afterwards anyway.

Nope, it's also useless
Comment 4 Carlos Garcia Campos 2015-10-29 05:20:33 PDT
Committed r191728: <http://trac.webkit.org/changeset/191728>
Comment 5 WebKit Commit Bot 2015-10-29 06:09:18 PDT
Re-opened since this is blocked by bug 150668
Comment 6 Carlos Garcia Campos 2015-10-30 04:21:54 PDT
Created attachment 264389 [details]
Patch for landing

Found the problem of the timeouts in the bots. I was cancelling the persistent source in RunLoop:stop(). In case of nested main loop, if there are pedning tasks in the parent loop, the source is invalidated and the pending tasks are never done. We don't really need to cancel the source on stop, since the main loop will be stopped anyway and the main context won't process more sources. So, this patch simply removes the set_ready_time to -1 line in RunLoop::stop()
Comment 7 Carlos Garcia Campos 2015-10-30 04:29:11 PDT
Committed r191786: <http://trac.webkit.org/changeset/191786>