Bug 102230 - [v8] Improve worker.postMessage() string performance: avoid utf8 conversion
Summary: [v8] Improve worker.postMessage() string performance: avoid utf8 conversion
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: noel gordon
URL:
Keywords:
Depends on: 96818 102243
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-14 07:26 PST by noel gordon
Modified: 2012-12-04 20:29 PST (History)
8 users (show)

See Also:


Attachments
Patch (4.74 KB, patch)
2012-11-14 07:30 PST, noel gordon
no flags Details | Formatted Diff | Diff
Patch (16.58 KB, patch)
2012-11-22 06:49 PST, noel gordon
no flags Details | Formatted Diff | Diff
Patch (16.41 KB, patch)
2012-11-29 00:48 PST, noel gordon
no flags Details | Formatted Diff | Diff
Patch (16.64 KB, patch)
2012-11-29 18:09 PST, noel gordon
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description noel gordon 2012-11-14 07:26:29 PST
SerializedScriptValue uses of v8::String::Utf8Value stringValue(value) is hot code transferring strings to/from workers.
Comment 1 noel gordon 2012-11-14 07:30:17 PST
Created attachment 174155 [details]
Patch
Comment 2 Adam Barth 2012-11-14 08:46:09 PST
Comment on attachment 174155 [details]
Patch

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

> Source/WebCore/bindings/v8/SerializedScriptValue.cpp:334
> +        doWriteUint32(static_cast<uint32_t>(length * 2));

2 -> sizeof(UChar) ?

> Source/WebCore/bindings/v8/SerializedScriptValue.cpp:335
> +        ensureSpace(length * 2);

Maybe we should put "length * 2" into a local variable since we use it a bunch?  Perhaps size?
Comment 3 Joshua Bell 2012-11-14 08:54:53 PST
I filed https://bugs.webkit.org/show_bug.cgi?id=102243 to track the issue this will cause with IndexedDB. We could land this first, but ideally 102243 would land at the same time or within a few days.
Comment 4 Joshua Bell 2012-11-14 08:58:13 PST
wireFormatVersion (line 244) needs to be incremented.
Comment 5 Alec Flett 2012-11-14 10:32:03 PST
Please wait for bug 96818 so you have a place to add tests and support backwards-compatible changes.
Comment 6 noel gordon 2012-11-19 23:18:28 PST
(In reply to comment #4)
> wireFormatVersion (line 244) needs to be incremented.

Considering bug 72198 and bug 76803, both of which added new serialization tag definitions, then why increment?  Seems we've never done so before.
Comment 7 Joshua Bell 2012-11-20 09:29:23 PST
(In reply to comment #6)
> (In reply to comment #4)
> > wireFormatVersion (line 244) needs to be incremented.
> 
> Considering bug 72198 and bug 76803, both of which added new serialization tag definitions, then why increment?  Seems we've never done so before.

The scenario we need to account for is:

* User installs build N+1
* User visits site using IndexedDB which writes SSVs to disk
* User "downgrades" to build N, without removing the "profile" (cookies, DBs, etc)
* User visits site; IndexedDB opens the backing store; some SSVs can't be parsed, surfaced as seemingly random data errors or inconsistencies

This scenario is unfortunately common enough that we've had to account for it by detecting the downgrade scenario. Our response in the IndexedDB code is rather severe (blow away the database) but the alternative is to block that origin's use of IDB, or surface what appears to web apps as data corruption.

The frequency of this scenario was not apparent to us until recently, or we would have implemented code such as https://bugs.webkit.org/show_bug.cgi?id=102243 earlier.

Suggestions for alternate approaches are welcome.
Comment 8 noel gordon 2012-11-22 06:35:13 PST
Thanks Josuha, I suppose IDB is like a really big cookie and users can blow their cookies (and IDB's) away any time. Applications have to deal with it: IDB storage is persistent, but it's not permanent.
Comment 9 noel gordon 2012-11-22 06:40:31 PST
(In reply to comment #2)
> (From update of attachment 174155 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=174155&action=review
> 
> > Source/WebCore/bindings/v8/SerializedScriptValue.cpp:334
> > +        doWriteUint32(static_cast<uint32_t>(length * 2));
> 
> 2 -> sizeof(UChar) ?

Done.

> > Source/WebCore/bindings/v8/SerializedScriptValue.cpp:335
> > +        ensureSpace(length * 2);
> 
> Maybe we should put "length * 2" into a local variable since we use it a bunch?  Perhaps size?

Good suggestion, I used size.  I also had to account for the length being VarInt encoded when working out if a paddingTag should be added.
Comment 10 noel gordon 2012-11-22 06:49:05 PST
Created attachment 175667 [details]
Patch
Comment 11 Alec Flett 2012-11-28 15:54:26 PST
Comment on attachment 175667 [details]
Patch

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

> Source/WebCore/bindings/v8/SerializedScriptValue.cpp:247
> +// Version 1: Version numbers manifested in space-time.

How about 
Version 0: Initial version, without explicit support for version numbers.
Version 1: support for object references (cycle detection)
Version 2:...

> LayoutTests/platform/chromium/fast/storage/serialized-script-value.html:149
> +var unicodeObject = {a: 'a', u: String.fromCharCode(0x03B1,0x03B2)};

you're going to need to add a backwards-compatible test here too - you'll have to run the test without your patch to generate the value first, then set the 3rd parameter to testSerialization to 'true'
Comment 12 noel gordon 2012-11-28 18:30:50 PST
(In reply to comment #11)
> (From update of attachment 175667 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=175667&action=review
> 
> > Source/WebCore/bindings/v8/SerializedScriptValue.cpp:247
> > +// Version 1: Version numbers manifested in space-time.
> 
> How about 
> Version 0: Initial version, without explicit support for version numbers.
> Version 1: support for object references (cycle detection)
> Version 2:...

How about (refer comment 6) I just write // Version 2: Added StringUCharTag for UChar v8 strings. since that's the only real fact I have.  "support for object references (cycle detection)" does not cover what happened before version 2.
Comment 13 noel gordon 2012-11-29 00:48:59 PST
Created attachment 176668 [details]
Patch
Comment 14 noel gordon 2012-11-29 00:53:46 PST
(In reply to comment #11)

> > LayoutTests/platform/chromium/fast/storage/serialized-script-value.html:149
> > +var unicodeObject = {a: 'a', u: String.fromCharCode(0x03B1,0x03B2)};
> 
> you're going to need to add a backwards-compatible test here too - you'll have to run the test without your patch to generate the value first, then set the 3rd parameter to testSerialization to 'true'

ok, I grabbed data for the test without my patch, and added that old data as the third argument of the test.  Didn't use a 'true', hope this is correct.
Comment 15 noel gordon 2012-11-29 01:00:23 PST
(In reply to comment #14)
Also fixed the existing test on http://trac.webkit.org/changeset/136085 so I could grab the data.
Comment 16 noel gordon 2012-11-29 18:09:10 PST
Created attachment 176875 [details]
Patch
Comment 17 Alec Flett 2012-11-30 13:28:41 PST
thanks for updating the tests - they lgtm now. (and yes, not sure why I thought the 3rd param was true/false)

(I'm realizing that what we really need is to support a whole list of "oldFormat" rather than just one - i.e. we should be supporting all the 0x01-prefixed values here. But you don't need to address that in this patch)
Comment 18 noel gordon 2012-12-04 16:44:04 PST
(In reply to comment #17)
> thanks for updating the tests - they lgtm now. (and yes, not sure why I thought the 3rd param was true/false)

: ) no worries.

> (I'm realizing that what we really need is to support a whole list of "oldFormat" rather than just one - i.e. we should be supporting all the 0x01-prefixed values here. But you don't need to address that in this patch)

Indeed.
Comment 19 noel gordon 2012-12-04 16:44:58 PST
(In reply to comment #3)
> I filed https://bugs.webkit.org/show_bug.cgi?id=102243 to track the issue this will cause with IndexedDB. We could land this first, but ideally 102243 would land at the same time or within a few days.

So is there anything more I need do here Josuha?
Comment 20 Joshua Bell 2012-12-04 16:47:30 PST
(In reply to comment #19)
> So is there anything more I need do here Josuha?

Not that I know of - I'd say go ahead and land it! I have 102243 ready to go... apart from tests and those will probably have to live in Chromium anyway. Users downgrading w/o deleting their profiles is not supported, just common enough that I want to be proactive so we don't have to land these together.
Comment 21 Eric Seidel (no email) 2012-12-04 16:57:39 PST
This looks reasonable, but I would love to have Dan Carney comment, given that he's been working in the v8-specific 8-bit string code so much lately.
Comment 22 Eric Seidel (no email) 2012-12-04 16:59:19 PST
Actually, this has little to do with v8-8bit strings, so Dan's comments although welcome, are not necessary.
Comment 23 Eric Seidel (no email) 2012-12-04 17:02:40 PST
Comment on attachment 176875 [details]
Patch

If Alec says LGTM, then LGTM too.
Comment 24 WebKit Review Bot 2012-12-04 20:29:18 PST
Comment on attachment 176875 [details]
Patch

Clearing flags on attachment: 176875

Committed r136624: <http://trac.webkit.org/changeset/136624>
Comment 25 WebKit Review Bot 2012-12-04 20:29:24 PST
All reviewed patches have been landed.  Closing bug.