Bug 84781 - objectProtoFuncToString creates new string every invocation
Summary: objectProtoFuncToString creates new string every invocation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Michael Saboff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-24 14:33 PDT by Michael Saboff
Modified: 2012-04-24 17:57 PDT (History)
1 user (show)

See Also:


Attachments
Patch (4.09 KB, patch)
2012-04-24 14:49 PDT, Michael Saboff
ggaren: review-
Details | Formatted Diff | Diff
Updated Patch with Suggested Fixes (3.91 KB, patch)
2012-04-24 15:35 PDT, Michael Saboff
ggaren: review+
webkit-ews: commit-queue-
Details | Formatted Diff | Diff
Updated patch with speculative Qt fix (3.92 KB, patch)
2012-04-24 16:44 PDT, Michael Saboff
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Saboff 2012-04-24 14:33:29 PDT
objectProtoFuncToString creates and returns a JSString with the contents of "[object <object_type]" (e.g. "[object Number]").  This creates a new string each time possibly increasing memory and using CPU.  This value should be created once and cached for each object.
Comment 1 Michael Saboff 2012-04-24 14:49:16 PDT
Created attachment 138653 [details]
Patch

This fails the style checker due to using a PassRefPtr as a local, but reused pattern from JSStringBuilder.h.
Comment 2 WebKit Review Bot 2012-04-24 14:51:01 PDT
Attachment 138653 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/ChangeLog', u'Source..." exit_code: 1
Source/JavaScriptCore/runtime/ObjectPrototype.cpp:260:  Local variables should never be PassRefPtr (see http://webkit.org/coding/RefPtr.html).  [readability/pass_ptr] [5]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Geoffrey Garen 2012-04-24 15:15:46 PDT
Comment on attachment 138653 [details]
Patch

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

Patch looks good, but some minor changes needed here before committing.

> Source/JavaScriptCore/runtime/ObjectPrototype.cpp:259
> +    if (!thisObject->structure()->hasObjectToStringValue()) {

Our typical style here is just to call objectToStringValue():
RefPtr<> toStringValue = thisObject->structure()->objectToStringValue();
if (!toStringValue) {
    ...
    toStringValue = ...
}
...

> Source/JavaScriptCore/runtime/ObjectPrototype.cpp:264
> +        thisObject->structure()->setObjectToStringValue(exec->globalData(), thisObject, jsNontrivialString(exec, result));

The appropriate pattern is to make the local a RefPtr, to avoid accidentally dereferencing NULL, and then use .release() when passing it to setObjectToStringValue here.

> Source/JavaScriptCore/runtime/Structure.cpp:797
> +#if 1

Please remove the #if.
Comment 4 Michael Saboff 2012-04-24 15:35:21 PDT
Created attachment 138669 [details]
Updated Patch with Suggested Fixes
Comment 5 Geoffrey Garen 2012-04-24 15:37:54 PDT
Comment on attachment 138669 [details]
Updated Patch with Suggested Fixes

r=me
Comment 6 Early Warning System Bot 2012-04-24 16:15:49 PDT
Comment on attachment 138669 [details]
Updated Patch with Suggested Fixes

Attachment 138669 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/12525366
Comment 7 Michael Saboff 2012-04-24 16:44:12 PDT
Created attachment 138686 [details]
Updated patch with speculative Qt fix
Comment 8 Michael Saboff 2012-04-24 17:57:32 PDT
Committed r115151: <http://trac.webkit.org/changeset/115151>