Bug 207747

Summary: NetworkLoadMetrics should be shared by multiple ResourceResponse instances
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: New BugsAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, dbates, ews-watchlist, galpeter, hi, japhet, joepeck, keith_miller, mark.lam, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch keith_miller: review+

Description Yusuke Suzuki 2020-02-13 23:24:09 PST
NetworkLoadMetrics should be shared by multiple ResourceResponse instances
Comment 1 Yusuke Suzuki 2020-02-13 23:40:24 PST
Created attachment 390732 [details]
Patch
Comment 2 Yusuke Suzuki 2020-02-13 23:40:57 PST
Comment on attachment 390732 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        has Vector<ResourceResponse> to replay response dispatching in the case of loading from BackForwardCache. The problem is

Note that this is one of the largest Vector in Membuster.
Comment 3 Radar WebKit Bug Importer 2020-02-13 23:47:11 PST
<rdar://problem/59452102>
Comment 4 Yusuke Suzuki 2020-02-14 00:59:31 PST
Created attachment 390737 [details]
Patch
Comment 5 Yusuke Suzuki 2020-02-14 01:06:53 PST
Created attachment 390738 [details]
Patch
Comment 6 Yusuke Suzuki 2020-02-14 01:15:31 PST
Created attachment 390739 [details]
Patch
Comment 7 Yusuke Suzuki 2020-02-14 01:21:36 PST
Created attachment 390740 [details]
Patch
Comment 8 Yusuke Suzuki 2020-02-14 01:36:16 PST
Created attachment 390741 [details]
Patch
Comment 9 Yusuke Suzuki 2020-02-14 02:13:33 PST
Created attachment 390743 [details]
Patch
Comment 10 Yusuke Suzuki 2020-02-14 02:16:01 PST
I'm also considering that making ResourceResponse RefCounted<>, but as a first step, I'll do NetworkLoadMetrics part.

I think we could make ResourceResponse RefCounted<> without changing much of things.
Due to WebKit2, we already initialize all the fields of ResourceResponse anyway.
So, we could make almost all part as immutable.
Comment 11 Yusuke Suzuki 2020-02-14 04:32:25 PST
Created attachment 390755 [details]
Patch
Comment 12 Keith Miller 2020-02-14 11:33:15 PST
Comment on attachment 390755 [details]
Patch

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

r=me with nits.

> Source/WebCore/ChangeLog:13
> +        While we sometimes copies it to modify some part of it, NetworkLoadMetrics is immutable. It is set when response is created,

nit: copies => copy

Also, what is "it" in "copies it"? A NeworkLoadMetrics or a ResourceResponse?

> Source/WebCore/ChangeLog:17
> +        This patch puts Box<NetworkLoadMetrics> in ResourceResponse to share it by all copied ResourceResponses. We do not make NetworkLoadMetrics

Nit: share it by => hare it with.

> Source/WebCore/ChangeLog:18
> +        RefCounted<> for now since some legit data structure embeds NetworkLoadMetrics. This patch adds ArgumentCoder for Box so that we

Nit: data structure embeds => data structures embed

Or did you mean that there is only on data structure that embed's NetworkLoadMetrics? If so can you name that class?

> Source/WebCore/platform/network/ResourceResponseBase.h:339
> +    if constexpr (Decoder::isIPCDecoder) {
> +        if (!decoder.decode(response.m_networkLoadMetrics))
> +            return false;
> +    }

Why bother with this change? Seems like the compiler will make this optimization anyway?

> Source/WebCore/platform/network/cocoa/NetworkLoadMetrics.mm:68
> +

Nit: remove newline here.
Comment 13 Yusuke Suzuki 2020-02-14 11:50:28 PST
Comment on attachment 390755 [details]
Patch

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

Thanks!

>> Source/WebCore/ChangeLog:13
>> +        While we sometimes copies it to modify some part of it, NetworkLoadMetrics is immutable. It is set when response is created,
> 
> nit: copies => copy
> 
> Also, what is "it" in "copies it"? A NeworkLoadMetrics or a ResourceResponse?

Fixed. DocumentLoader for example is copying ResourceResponse.

>> Source/WebCore/ChangeLog:17
>> +        This patch puts Box<NetworkLoadMetrics> in ResourceResponse to share it by all copied ResourceResponses. We do not make NetworkLoadMetrics
> 
> Nit: share it by => hare it with.

Fixed.

>> Source/WebCore/ChangeLog:18
>> +        RefCounted<> for now since some legit data structure embeds NetworkLoadMetrics. This patch adds ArgumentCoder for Box so that we
> 
> Nit: data structure embeds => data structures embed
> 
> Or did you mean that there is only on data structure that embed's NetworkLoadMetrics? If so can you name that class?

Fixed. Some of multiple classes are embedding NetworkLoadMetrics. So for now, I'm taking an easy path.

>> Source/WebCore/platform/network/ResourceResponseBase.h:339
>> +    }
> 
> Why bother with this change? Seems like the compiler will make this optimization anyway?

Encoder can be persistent coder (which generates bytes for disks).
We can omit implementation of persistent coder's NetworkLoadMetrics handling if we use `if constexpr`.

>> Source/WebCore/platform/network/cocoa/NetworkLoadMetrics.mm:68
>> +
> 
> Nit: remove newline here.

Fixed.
Comment 14 Yusuke Suzuki 2020-02-14 11:53:22 PST
Committed r256632: <https://trac.webkit.org/changeset/256632>