WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
81446
Cache the type string of JavaScript object
https://bugs.webkit.org/show_bug.cgi?id=81446
Summary
Cache the type string of JavaScript object
Benjamin Poulain
Reported
2012-03-17 00:35:27 PDT
Currently, we create a new string for every time we need the type string, we can do better than that.
Attachments
Patch
(16.96 KB, patch)
2012-03-17 00:43 PDT
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Alternative
(6.23 KB, patch)
2012-03-19 19:45 PDT
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Patch
(8.90 KB, patch)
2012-03-19 23:46 PDT
,
Benjamin Poulain
ggaren
: review+
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Benjamin Poulain
Comment 1
2012-03-17 00:43:49 PDT
Created
attachment 132452
[details]
Patch
Philippe Normand
Comment 2
2012-03-19 01:04:04 PDT
Comment on
attachment 132452
[details]
Patch
Attachment 132452
[details]
did not pass gtk-ews (gtk): Output:
http://queues.webkit.org/results/11988018
Gyuyoung Kim
Comment 3
2012-03-19 01:27:55 PDT
Comment on
attachment 132452
[details]
Patch
Attachment 132452
[details]
did not pass efl-ews (efl): Output:
http://queues.webkit.org/results/11982591
Early Warning System Bot
Comment 4
2012-03-19 11:13:28 PDT
Comment on
attachment 132452
[details]
Patch
Attachment 132452
[details]
did not pass qt-ews (qt): Output:
http://queues.webkit.org/results/11989193
Early Warning System Bot
Comment 5
2012-03-19 11:40:33 PDT
Comment on
attachment 132452
[details]
Patch
Attachment 132452
[details]
did not pass qt-wk2-ews (qt): Output:
http://queues.webkit.org/results/11980877
Build Bot
Comment 6
2012-03-19 12:28:00 PDT
Comment on
attachment 132452
[details]
Patch
Attachment 132452
[details]
did not pass win-ews (win): Output:
http://queues.webkit.org/results/11989243
Geoffrey Garen
Comment 7
2012-03-19 13:36:31 PDT
Comment on
attachment 132452
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=132452&action=review
Approach looks good. r- because it doesn't build on all platforms. Also, one comment below.
> Source/JavaScriptCore/runtime/JSValue.cpp:NaN > JSString* JSValue::toStringSlowCase(ExecState* exec) const
Please add common strings for all the JSValue::toString strings. These can be very common just like the type string case.
Geoffrey Garen
Comment 8
2012-03-19 13:38:33 PDT
... Did you consider use the SmallStrings storage instead? That has the nice side-benefit of using weak pointers, so its allocations don't fragment the heap.
Alexey Proskuryakov
Comment 9
2012-03-19 13:52:45 PDT
Will we have more trouble with profiling/Web Inspector, as we're getting additional "leaking" objects? SmallStrings used to confuse people looking at Caches debug window.
Oliver Hunt
Comment 10
2012-03-19 14:00:44 PDT
Comment on
attachment 132452
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=132452&action=review
> Source/JavaScriptCore/runtime/CommonIdentifiers.h:75 > - macro(displayName) \ > - macro(undefined) > + macro(displayName)
Why remove undefined from the common identifiers?
Geoffrey Garen
Comment 11
2012-03-19 14:09:38 PDT
> Will we have more trouble with profiling/Web Inspector, as we're getting additional "leaking" objects? > > SmallStrings used to confuse people looking at Caches debug window.
Like I said, SmallStrings are weak, so they disappear if not in use.
Benjamin Poulain
Comment 12
2012-03-19 14:11:21 PDT
(In reply to
comment #8
)
> ... Did you consider use the SmallStrings storage instead? That has the nice side-benefit of using weak pointers, so its allocations don't fragment the heap.
I did, but then we keep trashing the strings. I also considered CommonIdentifier + smallstrings. In the end, I went for the fastest in the benchmarks.
> > Source/JavaScriptCore/runtime/JSValue.cpp:NaN > > JSString* JSValue::toStringSlowCase(ExecState* exec) const > > Please add common strings for all the JSValue::toString strings. These can be very common just like the type string case.
I have a regression related to JSValue::toString() and I wanted to see that function separately. Your idea does not affect the regression so I can add that.
> > Source/JavaScriptCore/runtime/CommonIdentifiers.h:75 > > - macro(displayName) \ > > - macro(undefined) > > + macro(displayName) > > Why remove undefined from the common identifiers?
It is unused with this patch. The cached JSString is used instead.
Geoffrey Garen
Comment 13
2012-03-19 14:24:09 PDT
> > ... Did you consider use the SmallStrings storage instead? That has the nice side-benefit of using weak pointers, so its allocations don't fragment the heap. > > I did, but then we keep trashing the strings.
Can you elaborate on this? Using this technique, how much benchmark time is spent creating strings? If we assume that small strings occupy 1KB of space (which is pretty generous), and that the heap is only 512KB in size, the maximum time you'd ever expect to spend allocating small strings is on the order of 1/512 = 0.002%.
Benjamin Poulain
Comment 14
2012-03-19 19:45:48 PDT
Created
attachment 132749
[details]
Alternative
> Can you elaborate on this? Using this technique, how much benchmark time is spent creating strings? > > If we assume that small strings occupy 1KB of space (which is pretty generous), and that the heap is only 512KB in size, the maximum time you'd ever expect to spend allocating small strings is on the order of 1/512 = 0.002%.
Here is a patch for the other version. The trashing of strings was just an assumption. Profiling does not show any difference in the top functions between those two patches (fastFree() and fastMalloc() included). I have no clue why this is slower than the previous patch (by around 1.7%). I think that could just be my system, I am tempted to go with this because it is simpler... Any opinion?
Benjamin Poulain
Comment 15
2012-03-19 23:46:54 PDT
Created
attachment 132769
[details]
Patch
Benjamin Poulain
Comment 16
2012-03-19 23:49:24 PDT
Comment on
attachment 132769
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=132769&action=review
> Source/JavaScriptCore/runtime/SmallStrings.h:81 > + JSString* name##Keyword(JSGlobalData* globalData) const \
I suffixed with "Keyword" to avoid name clash with the C++ keywords. I considered the suffix "String", but "nullString" is too ambiguous in my opinion. Any suggestion for a better name is welcome.
Geoffrey Garen
Comment 17
2012-03-20 09:37:25 PDT
Comment on
attachment 132769
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=132769&action=review
r=me Hate to leave 1.7% on the table, but I do prefer the approach here for memory reasons, and the overall speedup is still quite large. I think it's reasonable to take the speedup and move on.
>> Source/JavaScriptCore/runtime/SmallStrings.h:81 >> + JSString* name##Keyword(JSGlobalData* globalData) const \ > > I suffixed with "Keyword" to avoid name clash with the C++ keywords. > I considered the suffix "String", but "nullString" is too ambiguous in my opinion. > > Any suggestion for a better name is welcome.
I'd prefer "name##String" because not all of these strings are, in fact, keywords.
Benjamin Poulain
Comment 18
2012-03-20 13:23:27 PDT
Committed
r111433
: <
http://trac.webkit.org/changeset/111433
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug