Ignore:
Timestamp:
03/06/12 15:54:46 (3 years ago)
Author:
haraken@chromium.org
Message:

[V8][Performance] Optimize V8 bindings for HTMLElement.classList,
Element.dataset and Node.attributes
https://bugs.webkit.org/show_bug.cgi?id=80376

Reviewed by Adam Barth.

This patch improves the performance of HTMLElement.classList, Element.dataset
and Node.attributes by 6.4 times, 7.1 times and 10.9 times, respectively.

Previously, a 'hiddenReferenceName' string was allocated on v8::Handle and
created every time the DOM attribute is accessed, in spite of the fact that
the 'hiddenReferenceName' string is static.

This patch moves the 'hiddenReferenceName' string to v8::Persistent and makes it static.
Also, this patch removes 'if (!elementValue.IsEmpty() && elementValue->IsObject())',
since if 'element' exists, it is guaranteed that 'elementValue' is not empty
and is an Object.

Performance tests: https://bugs.webkit.org/attachment.cgi?id=130283

AppleWebKit/JavaScriptCore:
div.classList : 382ms
div.classList.foo = 123 : 335ms
div.dataset : 403ms
div.dataset.foo = 123 : 5250ms
div.attributes : 183ms

Chromium/V8 (without this patch):
div.classList : 9140ms
div.classList.foo = 123 : 9086ms
div.dataset : 9930ms
div.dataset.foo = 123 : 49698ms
div.attributes : 13489ms

Chromium/V8 (with this patch):
div.classList : 1435ms
div.classList.foo = 123 : 1470ms
div.dataset : 1400ms
div.dataset.foo = 123 : 30396ms
div.attributes : 1242ms

No tests. No change in behavior.

  • bindings/v8/custom/V8DOMStringMapCustom.cpp: Modified as described above.

(WebCore::toV8):

  • bindings/v8/custom/V8DOMTokenListCustom.cpp: Ditto.

(WebCore::toV8):

  • bindings/v8/custom/V8NamedNodeMapCustom.cpp: Ditto.

(WebCore::toV8):

  • bindings/v8/V8HiddenPropertyName.cpp: Defined a hidden property name string statically

to optimize the macro.
(WebCore):
(WebCore::V8HiddenPropertyName::hiddenReferenceName):

  • bindings/v8/V8HiddenPropertyName.h: Modified to switch two prefixes "WebCore::HiddenProperty::"

and "WebCore::HiddenReference::", depending on whether a given name represents a hidden property
or a hidden reference.
(WebCore):
(V8HiddenPropertyName):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h

    r108596 r109969  
    3636namespace WebCore { 
    3737 
     38#define V8_HIDDEN_PROPERTY_PREFIX "WebCore::HiddenProperty::" 
     39#define V8_HIDDEN_REFERENCE_PREFIX "WebCore::HiddenReference::" 
     40 
    3841#define V8_HIDDEN_PROPERTIES(V) \ 
    39     V(objectPrototype) \ 
    40     V(listener) \ 
    41     V(attributeListener) \ 
    42     V(scriptState) \ 
    43     V(devtoolsInjectedScript) \ 
    44     V(sleepFunction) \ 
    45     V(toStringString) \ 
    46     V(event) \ 
    47     V(state) 
    48  
     42    V(objectPrototype, V8_HIDDEN_PROPERTY_PREFIX) \ 
     43    V(listener, V8_HIDDEN_PROPERTY_PREFIX) \ 
     44    V(attributeListener, V8_HIDDEN_PROPERTY_PREFIX) \ 
     45    V(scriptState, V8_HIDDEN_PROPERTY_PREFIX) \ 
     46    V(devtoolsInjectedScript, V8_HIDDEN_PROPERTY_PREFIX) \ 
     47    V(sleepFunction, V8_HIDDEN_PROPERTY_PREFIX) \ 
     48    V(toStringString, V8_HIDDEN_PROPERTY_PREFIX) \ 
     49    V(event, V8_HIDDEN_PROPERTY_PREFIX) \ 
     50    V(state, V8_HIDDEN_PROPERTY_PREFIX) \ 
     51    V(domStringMap, V8_HIDDEN_REFERENCE_PREFIX) \ 
     52    V(domTokenList, V8_HIDDEN_REFERENCE_PREFIX) \ 
     53    V(ownerNode, V8_HIDDEN_REFERENCE_PREFIX) 
    4954 
    5055    class V8HiddenPropertyName { 
    5156    public: 
    5257        V8HiddenPropertyName() { } 
    53 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name(); 
     58#define V8_DECLARE_PROPERTY(name, prefix) static v8::Handle<v8::String> name(); 
    5459        V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY); 
    5560#undef V8_DECLARE_PROPERTY 
     
    5964    private: 
    6065        static v8::Persistent<v8::String> createString(const char* key); 
    61 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name; 
    62         V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD); 
    63 #undef V8_DECLARE_FIELD 
    6466    }; 
    6567 
Note: See TracChangeset for help on using the changeset viewer.