Bug 137797 - ResourceRequest deserialization unnecessarily calls partitionName() on encoded cache partition
Summary: ResourceRequest deserialization unnecessarily calls partitionName() on encode...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Enhancement
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-16 16:45 PDT by Chris Dumez
Modified: 2014-10-21 14:07 PDT (History)
8 users (show)

See Also:


Attachments
Patch (4.37 KB, patch)
2014-10-16 17:02 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.36 KB, patch)
2014-10-17 14:26 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (16.77 KB, patch)
2014-10-20 17:08 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2014-10-16 16:45:47 PDT
ResourceRequest deserialization unnecessarily calls partitionName() on encoded cache partition. In the deserialization case, we already know the cache partition is a valid partition name so we should bypass the call to partitionName() for performance.

This is likely a regression from <http://trac.webkit.org/changeset/145161>.
Comment 1 Chris Dumez 2014-10-16 17:02:18 PDT
Created attachment 239984 [details]
Patch
Comment 2 Vicki Pfau 2014-10-17 14:15:25 PDT
Not exactly a regression. The deserialization of the cache partition was added in <http://trac.webkit.org/changeset/146544>, after that commit.

I'm a little leery of adding an argument to setCachePartition, but it doesn't look like there's much way around that. Also, isn't there a better place in the class to place the enum definition than between two function definitions?

Other than that minor nitpick, this looks good.
Comment 3 Chris Dumez 2014-10-17 14:22:35 PDT
(In reply to comment #2)
> Not exactly a regression. The deserialization of the cache partition was
> added in <http://trac.webkit.org/changeset/146544>, after that commit.

Right, sorry about that. I did not look much further, just saw that the patch made the argument processing mandatory by moving it from the callers to the method implementation.

> 
> I'm a little leery of adding an argument to setCachePartition, but it
> doesn't look like there's much way around that. Also, isn't there a better
> place in the class to place the enum definition than between two function
> definitions?

I see 3 possibilities:
1. Add an enum / bool argument as I did
2. Add a new setter without the argument processing. I initially wanted to do this but did not know how to call it.
3. Move the partitionName() to calls sites but I assumed we did not want to do that since it was this way and we changed it.

I am honestly OK with 1 or 2 if someone has a good name for the new setter.
Comment 4 Chris Dumez 2014-10-17 14:22:35 PDT
(In reply to comment #2)
> Not exactly a regression. The deserialization of the cache partition was
> added in <http://trac.webkit.org/changeset/146544>, after that commit.

Right, sorry about that. I did not look much further, just saw that the patch made the argument processing mandatory by moving it from the callers to the method implementation.

> 
> I'm a little leery of adding an argument to setCachePartition, but it
> doesn't look like there's much way around that. Also, isn't there a better
> place in the class to place the enum definition than between two function
> definitions?

I see 3 possibilities:
1. Add an enum / bool argument as I did
2. Add a new setter without the argument processing. I initially wanted to do this but did not know how to call it.
3. Move the partitionName() to calls sites but I assumed we did not want to do that since it was this way and we changed it.

I am honestly OK with 1 or 2 if someone has a good name for the new setter.
Comment 5 Chris Dumez 2014-10-17 14:26:25 PDT
Created attachment 240039 [details]
Patch
Comment 6 Alexey Proskuryakov 2014-10-20 10:19:02 PDT
Comment on attachment 240039 [details]
Patch

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

> Source/WebCore/platform/network/cf/ResourceRequest.h:-102
> +        enum CachePartitionNeedsValidationOrNot { CachePartitionDoesNotNeedValidation, CachePartitionNeedsValidation };
> +        void setCachePartition(const String& cachePartition, CachePartitionNeedsValidationOrNot needsValidation = CachePartitionNeedsValidation)
> +        {
> +            m_cachePartition = needsValidation ? partitionName(cachePartition) : cachePartition;
> +        }
>          const String& cachePartition() const { return m_cachePartition.isNull() ? emptyString() : m_cachePartition; }
> -        void setCachePartition(const String& cachePartition) { m_cachePartition = partitionName(cachePartition); }

The existing code is semantically wrong. This function doesn't take a partition name, it takes a domain name. Both happen to be String objects and to follow a domain name format, but this is accidental, and only confuses matters. Domains and partition names are different things, and should never be confused.

So it's not about validation, it's about making a partition name from a domain name.

Talking about a better design on IRC now - I think that we should have setCachePartition be a simple setter (perhaps with as ASSERT), and callers would create a partition name from domain name.
Comment 7 Chris Dumez 2014-10-20 17:08:34 PDT
Created attachment 240157 [details]
Patch
Comment 8 Chris Dumez 2014-10-20 17:09:24 PDT
New proposal including refactoring of the existing code, after discussing this over with Alexey and Jeffrey.
Comment 9 WebKit Commit Bot 2014-10-20 19:10:47 PDT
Comment on attachment 240157 [details]
Patch

Clearing flags on attachment: 240157

Committed r174921: <http://trac.webkit.org/changeset/174921>
Comment 10 WebKit Commit Bot 2014-10-20 19:10:54 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Jer Noble 2014-10-21 14:05:14 PDT
(In reply to comment #10)
> All reviewed patches have been landed.  Closing bug.

This caused a link failure due to the renaming of cachePartition. WebCore.exp.in needs to be updated to match the new name.
Comment 12 Chris Dumez 2014-10-21 14:07:57 PDT
(In reply to comment #11)
> (In reply to comment #10)
> > All reviewed patches have been landed.  Closing bug.
> 
> This caused a link failure due to the renaming of cachePartition.
> WebCore.exp.in needs to be updated to match the new name.

I fixed that a while ago:
https://trac.webkit.org/r174994
https://trac.webkit.org/r174995