Summary: | Cache the type string of JavaScript object | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Benjamin Poulain <benjamin> | ||||||||
Component: | JavaScriptCore | Assignee: | Benjamin Poulain <benjamin> | ||||||||
Status: | RESOLVED FIXED | ||||||||||
Severity: | Normal | CC: | ap, barraclough, ggaren, gustavo, pnormand, xan.lopez | ||||||||
Priority: | P2 | ||||||||||
Version: | 528+ (Nightly build) | ||||||||||
Hardware: | Unspecified | ||||||||||
OS: | Unspecified | ||||||||||
Attachments: |
|
Description
Benjamin Poulain
2012-03-17 00:35:27 PDT
Created attachment 132452 [details]
Patch
Comment on attachment 132452 [details] Patch Attachment 132452 [details] did not pass gtk-ews (gtk): Output: http://queues.webkit.org/results/11988018 Comment on attachment 132452 [details] Patch Attachment 132452 [details] did not pass efl-ews (efl): Output: http://queues.webkit.org/results/11982591 Comment on attachment 132452 [details] Patch Attachment 132452 [details] did not pass qt-ews (qt): Output: http://queues.webkit.org/results/11989193 Comment on attachment 132452 [details] Patch Attachment 132452 [details] did not pass qt-wk2-ews (qt): Output: http://queues.webkit.org/results/11980877 Comment on attachment 132452 [details] Patch Attachment 132452 [details] did not pass win-ews (win): Output: http://queues.webkit.org/results/11989243 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. ... 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. 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. 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? > 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.
(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. > > ... 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%.
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? Created attachment 132769 [details]
Patch
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. 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. Committed r111433: <http://trac.webkit.org/changeset/111433> |