Bug 186820 - Reduce size of WebCore::URL
Summary: Reduce size of WebCore::URL
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: 187577
Blocks:
  Show dependency treegraph
 
Reported: 2018-06-19 14:35 PDT by Alex Christensen
Modified: 2018-08-22 19:00 PDT (History)
14 users (show)

See Also:


Attachments
Patch (28.78 KB, patch)
2018-06-19 14:39 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (28.84 KB, patch)
2018-06-19 14:39 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (29.95 KB, patch)
2018-07-11 11:48 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (31.90 KB, patch)
2018-07-12 13:25 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (32.01 KB, patch)
2018-07-12 13:38 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (32.13 KB, patch)
2018-07-12 14:38 PDT, 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 2018-06-19 14:35:26 PDT
Reduce size of WebCore::URL
Comment 1 Alex Christensen 2018-06-19 14:39:06 PDT
Created attachment 343099 [details]
Patch
Comment 2 Alex Christensen 2018-06-19 14:39:38 PDT
Created attachment 343100 [details]
Patch
Comment 3 Fujii Hironori 2018-06-29 00:05:22 PDT
Comment on attachment 343100 [details]
Patch

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

I'm not a reviewer. This is an informal review.

> Source/WebCore/platform/URL.cpp:167
> +    if (!m_portLength)

Nit: You changed the logic. "m_portLength <= 1" is the equivalent with the orignal because m_portLength includes ':'.

> Source/WebCore/platform/URLParser.cpp:2610
> +        RELEASE_ASSERT(portLength <= URL::maxPortLength);

You added RELEASE_ASSERT here. What will happen with a URL like 'http://example.com:0000080/'?
Comment 4 Yusuke Suzuki 2018-06-29 03:16:02 PDT
Comment on attachment 343100 [details]
Patch

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

> Source/WebCore/platform/URL.h:225
>      bool m_isValid : 1;
>      bool m_protocolIsInHTTPFamily : 1;
>      bool m_cannotBeABaseURL : 1;

I think MSVC does not pack small-sized members if they have different types. (maybe). I think this is why EWS is red.
If it is correct, you can avoid this behavior by changing them to `unsigned`.
At that time, we should take care of the types of these fields. For example, URL::encode and URL::decode should take extra care.

> Source/WebCore/platform/URL.h:245
>  void URL::encode(Encoder& encoder) const

URL::encode does not encode m_cannotBeABaseURL. Is it correct?

> Source/WebCore/platform/URL.h:286
>      if (!decoder.decode(protocolIsInHTTPFamily))

URL::decode does not handle m_cannotBeABaseURL, is it correct?

> Source/WebCore/platform/URLParser.cpp:2701
> -            m_url.m_portEnd = currentPosition(iterator);
> +            unsigned portLength = currentPosition(iterator) - m_url.m_hostEnd;
> +            RELEASE_ASSERT(portLength <= URL::maxPortLength);
> +            m_url.m_portLength = portLength;

I think `m_url.m_portLength = 0` since `iterator.atEnd()` immediately after setting `m_url.m_hostEnd = currentPosition(iterator);`, correct?

> Source/WebCore/platform/URLParser.cpp:2724
> -                m_url.m_portEnd = currentPosition(iterator);
> +                unsigned portLength = currentPosition(iterator) - m_url.m_hostEnd;
> +                RELEASE_ASSERT(portLength <= URL::maxPortLength);
> +                m_url.m_portLength = portLength;

Ditto.

> Source/WebCore/platform/URLParser.cpp:2789
> -            m_url.m_portEnd = currentPosition(iterator);
> +            unsigned portLength = currentPosition(iterator) - m_url.m_hostEnd;
> +            RELEASE_ASSERT(portLength <= URL::maxPortLength);
> +            m_url.m_portLength = portLength;

Ditto.

> Source/WebCore/platform/URLParser.cpp:2803
> -    m_url.m_portEnd = currentPosition(iterator);
> +    unsigned portLength = currentPosition(iterator) - m_url.m_hostEnd;
> +    RELEASE_ASSERT(portLength <= URL::maxPortLength);
> +    m_url.m_portLength = portLength;

Ditto.
Comment 5 Alex Christensen 2018-07-11 11:08:36 PDT
Comment on attachment 343100 [details]
Patch

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

>> Source/WebCore/platform/URL.cpp:167
>> +    if (!m_portLength)
> 
> Nit: You changed the logic. "m_portLength <= 1" is the equivalent with the orignal because m_portLength includes ':'.

This is true, but a URL with a : but no numeric port after is invalid now.

>> Source/WebCore/platform/URLParser.cpp:2610
>> +        RELEASE_ASSERT(portLength <= URL::maxPortLength);
> 
> You added RELEASE_ASSERT here. What will happen with a URL like 'http://example.com:0000080/'?

The port should be normalized to 80.  I'll add a test just in case.
Comment 6 Alex Christensen 2018-07-11 11:48:56 PDT
Created attachment 344775 [details]
Patch
Comment 7 WebKit Commit Bot 2018-07-11 13:48:57 PDT
Comment on attachment 344775 [details]
Patch

Clearing flags on attachment: 344775

Committed r233742: <https://trac.webkit.org/changeset/233742>
Comment 8 WebKit Commit Bot 2018-07-11 13:48:58 PDT
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2018-07-11 13:49:37 PDT
<rdar://problem/42087508>
Comment 10 Darin Adler 2018-07-11 19:37:58 PDT
Comment on attachment 344775 [details]
Patch

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

Seems to me the even more important optimization is to make sure we don’t keep URLs around all the time; how often do we need a pre-parsed string with offsets stored just so we don’t have to scan for special characters again. I kind of wish there was something between String and URL.

> Source/WebCore/platform/URL.h:227
> +    // This is out of order to allign the bits better. The port is after the host.

Typo in the word "align" here.
Comment 11 Daniel Bates 2018-07-11 20:33:37 PDT
Comment on attachment 344775 [details]
Patch

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

> Source/WebCore/platform/URL.h:254
> -    encoder << m_schemeEnd;
> +    encoder << static_cast<bool>(m_cannotBeABaseURL);
> +    encoder << static_cast<unsigned>(m_schemeEnd);
>      encoder << m_userStart;

This is not a binary compatible change (*) and as a result I am hitting the ASSERT_NOT_REACHED() in URL::decode() when I access http://forums.swift.org. The Service Worker registration code that runs in the Storage Process executes and tries to import registration records from disk.

(*) We seem to have inadvertently tied the representation of a URL to what we write when persisting a Service Worker imported script to disk among other things. This logic was added in bug #182444.
Comment 12 WebKit Commit Bot 2018-07-11 20:35:28 PDT
Re-opened since this is blocked by bug 187577
Comment 13 Daniel Bates 2018-07-11 20:42:21 PDT
(In reply to WebKit Commit Bot from comment #12)
> Re-opened since this is blocked by bug 187577

See backtrace and frame variables in bug #187577.
Comment 14 Chris Dumez 2018-07-11 20:46:11 PDT
(In reply to Daniel Bates from comment #13)
> (In reply to WebKit Commit Bot from comment #12)
> > Re-opened since this is blocked by bug 187577
> 
> See backtrace and frame variables in bug #187577.

Looks like we'll see to fix service worker persistence first :/
Comment 15 Alex Christensen 2018-07-12 11:27:14 PDT
(In reply to Chris Dumez from comment #14)
> Looks like we'll see to fix service worker persistence first :/
Couldn't we just increment the version number of the binary format somewhere like we do with the disk cache?
Comment 16 Chris Dumez 2018-07-12 12:37:39 PDT
(In reply to Alex Christensen from comment #15)
> (In reply to Chris Dumez from comment #14)
> > Looks like we'll see to fix service worker persistence first :/
> Couldn't we just increment the version number of the binary format somewhere
> like we do with the disk cache?

I believe the disk cache uses persistent coders that are distinct from IPC coders specifically to avoid this. I think we need a persistent coder for URL and use that one, instead of using the IPC one.
Comment 17 youenn fablet 2018-07-12 13:05:32 PDT
(In reply to Alex Christensen from comment #15)
> (In reply to Chris Dumez from comment #14)
> > Looks like we'll see to fix service worker persistence first :/
> Couldn't we just increment the version number of the binary format somewhere
> like we do with the disk cache?

We should do that and serialize URLs as strings in the persistent script map at the same time.
Comment 18 Alex Christensen 2018-07-12 13:25:32 PDT
Created attachment 344877 [details]
Patch
Comment 19 Alex Christensen 2018-07-12 13:38:07 PDT
Created attachment 344878 [details]
Patch
Comment 20 youenn fablet 2018-07-12 14:14:50 PDT
Comment on attachment 344878 [details]
Patch

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

> Source/WebCore/platform/URL.cpp:461
> +    URLParser parser(m_string.left(m_hostEnd) + m_string.substring(m_hostEnd + m_portLength));

That is not great to create three strings here.
Could we try to use StringViews instead of left and substring?

> Source/WebCore/platform/URL.cpp:473
> +    URLParser parser(makeString(m_string.left(portStart), (colonNeeded ? ":" : ""), String::number(i), m_string.substring(m_hostEnd + m_portLength)));

Ditto here.

> Source/WebCore/platform/URL.cpp:513
> +    builder.append(m_string.substring(m_hostEnd + m_portLength));

I believe StringBuilder is taking StringView as input.
Comment 21 Alex Christensen 2018-07-12 14:38:56 PDT
Created attachment 344883 [details]
Patch
Comment 22 Alex Christensen 2018-07-12 17:28:49 PDT
http://trac.webkit.org/r233789
Comment 23 Truitt Savell 2018-07-13 08:29:59 PDT
An API test failure was introduced in r233789 <https://trac.webkit.org/changeset/233789/webkit>

Test Output:

Test suite failed

Failed

    TestWebKitAPI.WebKit.CustomDataStorePathsVersusCompletionHandlers
        
        /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:264
        Value of: 1
        Expected: (int)dataRecords.count
        Which is: 0
        
        
        /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:273
        Value of: 1
        Expected: (int)dataRecords.count
        Which is: 0
Comment 24 Chris Dumez 2018-07-13 08:34:57 PDT
(In reply to Truitt Savell from comment #23)
> An API test failure was introduced in r233789
> <https://trac.webkit.org/changeset/233789/webkit>
> 
> Test Output:
> 
> Test suite failed
> 
> Failed
> 
>     TestWebKitAPI.WebKit.CustomDataStorePathsVersusCompletionHandlers
>         
>        
> /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/WebsiteDataStoreCustomPaths.mm:264
>         Value of: 1
>         Expected: (int)dataRecords.count
>         Which is: 0
>         
>         
>        
> /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/WebsiteDataStoreCustomPaths.mm:273
>         Value of: 1
>         Expected: (int)dataRecords.count
>         Which is: 0

We need to update the pre-baked service worker registration database that the API tests are using, since the format has changed in this patch.
Comment 25 Chris Dumez 2018-07-13 08:36:53 PDT
(In reply to Chris Dumez from comment #24)
> (In reply to Truitt Savell from comment #23)
> > An API test failure was introduced in r233789
> > <https://trac.webkit.org/changeset/233789/webkit>
> > 
> > Test Output:
> > 
> > Test suite failed
> > 
> > Failed
> > 
> >     TestWebKitAPI.WebKit.CustomDataStorePathsVersusCompletionHandlers
> >         
> >        
> > /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/
> > WebKitCocoa/WebsiteDataStoreCustomPaths.mm:264
> >         Value of: 1
> >         Expected: (int)dataRecords.count
> >         Which is: 0
> >         
> >         
> >        
> > /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/
> > WebKitCocoa/WebsiteDataStoreCustomPaths.mm:273
> >         Value of: 1
> >         Expected: (int)dataRecords.count
> >         Which is: 0
> 
> We need to update the pre-baked service worker registration database that
> the API tests are using, since the format has changed in this patch.

Tools//TestWebKitAPI/Tests/WebKitCocoa/SimpleServiceWorkerRegistrations-2.sqlite3
Tools//TestWebKitAPI/Tests/WebKitCocoa/SimpleServiceWorkerRegistrations-2.sqlite3-shm
Tools//TestWebKitAPI/Tests/WebKitCocoa/SimpleServiceWorkerRegistrations-2.sqlite3-wal
Comment 26 Chris Dumez 2018-07-13 08:42:25 PDT
(In reply to Chris Dumez from comment #25)
> (In reply to Chris Dumez from comment #24)
> > (In reply to Truitt Savell from comment #23)
> > > An API test failure was introduced in r233789
> > > <https://trac.webkit.org/changeset/233789/webkit>
> > > 
> > > Test Output:
> > > 
> > > Test suite failed
> > > 
> > > Failed
> > > 
> > >     TestWebKitAPI.WebKit.CustomDataStorePathsVersusCompletionHandlers
> > >         
> > >        
> > > /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/
> > > WebKitCocoa/WebsiteDataStoreCustomPaths.mm:264
> > >         Value of: 1
> > >         Expected: (int)dataRecords.count
> > >         Which is: 0
> > >         
> > >         
> > >        
> > > /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/
> > > WebKitCocoa/WebsiteDataStoreCustomPaths.mm:273
> > >         Value of: 1
> > >         Expected: (int)dataRecords.count
> > >         Which is: 0
> > 
> > We need to update the pre-baked service worker registration database that
> > the API tests are using, since the format has changed in this patch.
> 
> Tools//TestWebKitAPI/Tests/WebKitCocoa/SimpleServiceWorkerRegistrations-2.
> sqlite3
> Tools//TestWebKitAPI/Tests/WebKitCocoa/SimpleServiceWorkerRegistrations-2.
> sqlite3-shm
> Tools//TestWebKitAPI/Tests/WebKitCocoa/SimpleServiceWorkerRegistrations-2.
> sqlite3-wal

I am looking into this now.
Comment 27 Chris Dumez 2018-07-13 09:14:01 PDT
Committed r233798: <https://trac.webkit.org/changeset/233798>
Comment 28 Antti Koivisto 2018-08-21 08:23:37 PDT
Comment on attachment 344883 [details]
Patch

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

> Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h:111
>      // Incrementing this number will delete all existing cache content for everyone. Do you really need to do it?
> -    static const unsigned version = 12;
> +    static const unsigned version = 13;

Did you, really?
Comment 29 Fujii Hironori 2018-08-22 19:00:12 PDT
(In reply to Antti Koivisto from comment #28)
> Did you, really?

Did you see Bug 187577 mentioned in above comments?