Bug 205011

Summary: Make preconnectTo()'s completionHandler optional
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, commit-queue, cturner, darin, ggaren, koivisto, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Chris Dumez 2019-12-09 08:12:09 PST
Make preconnectTo()'s completionHandler optional, so that the network process does not unnecessarily send an IPC back if the client is not interested.
Comment 1 Chris Dumez 2019-12-09 08:13:07 PST
Created attachment 385149 [details]
Patch
Comment 2 Chris Dumez 2019-12-09 14:05:34 PST
Created attachment 385189 [details]
Patch
Comment 3 Darin Adler 2019-12-09 15:20:12 PST
Comment on attachment 385149 [details]
Patch

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

> Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h:191
> +    void preconnectTo(Optional<uint64_t>&& preconnectionIdentifier, NetworkResourceLoadParameters&&);

Seems like overkill to use an rvalue reference for an Optional. Just pass by value maybe?
Comment 4 Chris Dumez 2019-12-09 15:21:49 PST
(In reply to Darin Adler from comment #3)
> Comment on attachment 385149 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=385149&action=review
> 
> > Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h:191
> > +    void preconnectTo(Optional<uint64_t>&& preconnectionIdentifier, NetworkResourceLoadParameters&&);
> 
> Seems like overkill to use an rvalue reference for an Optional. Just pass by
> value maybe?

I thought our policy was 'pass by value' only if <= 64 bit because it is faster. Do I remember wrong?
Comment 5 Darin Adler 2019-12-09 15:30:23 PST
Comment on attachment 385149 [details]
Patch

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

>>> Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h:191
>>> +    void preconnectTo(Optional<uint64_t>&& preconnectionIdentifier, NetworkResourceLoadParameters&&);
>> 
>> Seems like overkill to use an rvalue reference for an Optional. Just pass by value maybe?
> 
> I thought our policy was 'pass by value' only if <= 64 bit because it is faster. Do I remember wrong?

Anders told me a long time ago that passing StringView by value was faster than by reference. I never questioned that or tested it.
Comment 6 Chris Dumez 2019-12-09 16:03:34 PST
Created attachment 385199 [details]
Patch
Comment 7 Chris Dumez 2019-12-10 08:13:10 PST
Comment on attachment 385199 [details]
Patch

Clearing flags on attachment: 385199

Committed r253325: <https://trac.webkit.org/changeset/253325>
Comment 8 Chris Dumez 2019-12-10 08:13:11 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2019-12-10 08:14:43 PST
<rdar://problem/57794165>
Comment 10 Charlie Turner 2020-03-18 05:29:33 PDT
Comment on attachment 385199 [details]
Patch

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

> Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:669
> +    Optional<uint64_t> preconnectionIdentifier;

I'm not on a platform where I can test preconnection logic (!ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) && !ENABLE(SERVER_PRECONNECT)), but could we avoid the .send(...) at the bottom of this function if (!preconnectionIdentifier) ? I'm getting many internal errors thrown to stderr without extra information in NetworkConnectionToWebProcess::preconnectTo due to the internalError being called because of the network process side of preconnectTo being essentially a no-op on my platform. I could flag-off the call directly in preconnectTo, but reading the callsites it looked like maybe the IPC send could be avoided all-together in this case.
Comment 11 Chris Dumez 2020-03-18 08:35:12 PDT
(In reply to Charlie Turner from comment #10)
> Comment on attachment 385199 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=385199&action=review
> 
> > Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:669
> > +    Optional<uint64_t> preconnectionIdentifier;
> 
> I'm not on a platform where I can test preconnection logic
> (!ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) && !ENABLE(SERVER_PRECONNECT)), but
> could we avoid the .send(...) at the bottom of this function if
> (!preconnectionIdentifier) ? I'm getting many internal errors thrown to
> stderr without extra information in
> NetworkConnectionToWebProcess::preconnectTo due to the internalError being
> called because of the network process side of preconnectTo being essentially
> a no-op on my platform. I could flag-off the call directly in preconnectTo,
> but reading the callsites it looked like maybe the IPC send could be avoided
> all-together in this case.

If your port does not support preconnect, then yes, avoiding sending out the IPC is a good idea. If you write a patch for this, I'd be happy to review it. That said, it may not be a lot of work to add preconnect support for your port? :) Preconnect is a very useful optimization that WebKit is using more and more.
Comment 12 Charlie Turner 2020-03-20 09:29:00 PDT
(In reply to Chris Dumez from comment #11)
> If your port does not support preconnect, then yes, avoiding sending out the
> IPC is a good idea. If you write a patch for this, I'd be happy to review
> it. That said, it may not be a lot of work to add preconnect support for
> your port? :) Preconnect is a very useful optimization that WebKit is using
> more and more.

I'll pass that on, thanks!

It turned out that this spurious error and the extra send() is already correctly avoided in trunk, being correctly conditioned out on the linkPreconnectEnabled web setting. In the WebKitGTK 2.28 release WebPage::loadRequest was calling preconnectTo outside of such a condition, which gave the errors. Sorry for not spotting master vs 2.28 difference earlier, but at least the question served a reminder we should implement preconnect hint.  :)