Bug 179800 - Use RunLoop and Mode from NetworkingContext if they are given
Summary: Use RunLoop and Mode from NetworkingContext if they are given
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on:
Blocks: 179809
  Show dependency treegraph
 
Reported: 2017-11-16 15:41 PST by Alex Christensen
Modified: 2017-11-17 13:33 PST (History)
10 users (show)

See Also:


Attachments
Patch (2.29 KB, patch)
2017-11-16 15:57 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (6.84 KB, patch)
2017-11-16 17:01 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (14.70 KB, patch)
2017-11-17 11:50 PST, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2017-11-16 15:41:33 PST
Always call performSelectorOnMainThread if we call callOnMainThread with a valid SchedulePairHashSet
Comment 1 Alex Christensen 2017-11-16 15:57:06 PST
Created attachment 327119 [details]
Patch
Comment 2 Geoffrey Garen 2017-11-16 16:12:38 PST
Comment on attachment 327119 [details]
Patch

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

> Source/WTF/wtf/MainThread.cpp:158
> +    if (pairs || needToSchedule)
>          scheduleDispatchFunctionsOnMainThread(pairs);

This fixes the bug in one direction but not the other: If items supplying pairs are scheduled, a callOnMainThread that does not supply pairs will not be scheduled.

There's also another bug in this code: When we ultimately fire, we'll run tasks regardless of their pairs, including tasks that shouldn't run right now.
Comment 3 Geoffrey Garen 2017-11-16 16:20:05 PST
Maybe a good way to fix this is to say that, if you do not supply pairs, you get the function queue optimizations, but if you do supply pairs, you just invoke performSelectorOnMainThread directly without any amortization. We believe that use of pairs is rare and not performance-critical, so this might be the simplest solution.

So, you would break out a helper function called scheduleDispatchFunctionOnMainThread(Function<void()>&&, SchedulePairHashSet*), and it it would do the Right Thing (TM). This would also make it trivial to honor not just the run loop mode but also the run loop.
Comment 4 Alex Christensen 2017-11-16 17:01:51 PST
Created attachment 327131 [details]
Patch
Comment 5 Geoffrey Garen 2017-11-16 17:28:26 PST
r=me

Can we remove SchedulePairHashSet support from MainThread.h now?

> Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:54
> +static void callOnMainThreadOrSchedule(Function<void()>&& function, SchedulePairHashSet* pairs)

I don't think "OrSchedule" adds value to this name. In all cases, we end up scheduling something on a run loop.

> Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:66
> +    } else
> +        callOnMainThread(WTFMove(function));

I think this function would read more clearly if the !pairs case came first as an early return. Then the rest of the logic doesn't need indentation.
Comment 6 Alex Christensen 2017-11-16 17:36:35 PST
https://trac.webkit.org/changeset/224952/webkit

I'll do Geoff's suggested renaming and cleanups in a followup patch
Comment 7 Radar WebKit Bug Importer 2017-11-16 17:40:58 PST
<rdar://problem/35604879>
Comment 8 Alex Christensen 2017-11-16 18:02:55 PST
Cleaning up in https://bugs.webkit.org/show_bug.cgi?id=179809
Comment 9 Ryan Haddad 2017-11-17 09:51:57 PST
This test introduced 80+ LayoutTest failures/timeouts on WK1 bots:

https://build.webkit.org/builders/Apple%20Sierra%20Release%20WK1%20%28Tests%29/builds/6192
Comment 10 Ryan Haddad 2017-11-17 09:53:00 PST
(In reply to Ryan Haddad from comment #9)
> This test introduced 80+ LayoutTest failures/timeouts on WK1 bots:
> 
> https://build.webkit.org/builders/
> Apple%20Sierra%20Release%20WK1%20%28Tests%29/builds/6192
s/test/change
Comment 11 Matt Lewis 2017-11-17 09:59:01 PST
The test WebKitLegacy.ScheduleInRunLoop does pass as stated in the changelog, but it now intermittently times out on macOS Debug platforms:
https://build.webkit.org/builders/Apple%20Sierra%20Debug%20WK2%20(Tests)/builds/4058/steps/run-api-tests/logs/stdio
https://build.webkit.org/builders/Apple%20Sierra%20Debug%20WK2%20(Tests)/builds/4058
Comment 12 Ryan Haddad 2017-11-17 10:02:33 PST
Reverted r224952 for reason:

This change introduced LayoutTest failures on WK1.

Committed r224969: <https://trac.webkit.org/changeset/224969>
Comment 13 Ryan Haddad 2017-11-17 11:06:19 PST
(In reply to Ryan Haddad from comment #12)
> Reverted r224952 for reason:
> 
> This change introduced LayoutTest failures on WK1.
> 
> Committed r224969: <https://trac.webkit.org/changeset/224969>
Tests are green again after the rollout, so this was indeed the cause.
https://build.webkit.org/builders/Apple%20El%20Capitan%20Release%20WK1%20%28Tests%29/builds/6360
Comment 14 Alex Christensen 2017-11-17 11:50:23 PST
Created attachment 327206 [details]
Patch
Comment 15 Geoffrey Garen 2017-11-17 11:59:09 PST
Does this patch need review?
Comment 16 Alex Christensen 2017-11-17 13:28:50 PST
This is just a slight modification of the previous patch to only CFRunLoopPerformBlock if we're scheduled in a custom mode.  It works with UIWebView, it works with the app that's causing this bug, and it works with the WebKit tests, unlike the previous attempt.
Comment 17 Alex Christensen 2017-11-17 13:33:42 PST
http://trac.webkit.org/r224982