Ignore:
Timestamp:
Jan 16, 2010, 11:18:38 PM (15 years ago)
Author:
[email protected]
Message:

2010-01-16 Maciej Stachowiak <[email protected]>

Reviewed by Oliver Hunt.

Cache JS string values made from DOM strings (Dromaeo speedup)
https://bugs.webkit.org/show_bug.cgi?id=33768
<rdar://problem/7353576>

  • runtime/JSString.h: (JSC::jsStringWithFinalizer): Added new mechanism for a string to have an optional finalizer callback, for the benefit of weak-referencing caches. (JSC::): (JSC::Fiber::JSString): (JSC::Fiber::~JSString):
  • runtime/JSString.cpp: (JSC::JSString::resolveRope): Clear fibers so this doesn't look like a string with a finalizer.
  • runtime/WeakGCMap.h: Include "Collector.h" to make this header includable by itself.

2010-01-16 Maciej Stachowiak <[email protected]>

Reviewed by Oliver Hunt.

Cache JS string values made from DOM strings (Dromaeo speedup)
https://bugs.webkit.org/show_bug.cgi?id=33768
<rdar://problem/7353576>


  • Plugins/Hosted/ProxyInstance.mm: (WebKit::ProxyInstance::stringValue): Explicitly make a String, since char* is now ambiguous.

2010-01-16 Maciej Stachowiak <[email protected]>

Reviewed by Oliver Hunt.

Cache JS string values made from DOM strings (Dromaeo speedup)
https://bugs.webkit.org/show_bug.cgi?id=33768
<rdar://problem/7353576>

Added a new cache for JSString values that are created from Strings or AtomicStrings
in the DOM. It's common for the same string to be retrieved from the DOM repeatedly,
and it is wasteful to make a new JS-level string value every time.


The string cache is per-world, and thus thread-safe and not a
vector for accidental information exchange.


~30% speedup on Dromaeo Attributes test, also substantially helps other Dromaeo DOM tests.

  • bindings/js/JSDOMBinding.cpp: (WebCore::jsStringCache): Helper function to get the string cache for the current world. (WebCore::jsString): Some new overloads including the caching version. (WebCore::stringWrapperDestroyed): Finalizer callback - remove from relevant caches.
  • bindings/js/JSDOMBinding.h: (WebCore::jsString): Prototype new overloads (and define a few inline).
  • bindings/js/JSJavaScriptCallFrameCustom.cpp: (WebCore::JSJavaScriptCallFrame::type): Explicitly make a UString.
  • bindings/js/ScriptFunctionCall.cpp: (WebCore::ScriptFunctionCall::appendArgument): Ditto.
  • WebCore.base.exp: Add new JSString overloads that WebCore gets to see.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSString.h

    r52956 r53371  
    6060    JSString* jsOwnedString(ExecState*, const UString&);
    6161
     62    typedef void (*JSStringFinalizerCallback)(JSString*, void* context);
     63    JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);
     64
    6265    class JS_EXPORTCLASS JSString : public JSCell {
    6366    public:
     
    7275            class Fiber {
    7376            public:
    74                 Fiber() {}
     77                Fiber() : m_value(0) {}
    7578                Fiber(UString::Rep* string) : m_value(reinterpret_cast<intptr_t>(string)) {}
    7679                Fiber(Rope* rope) : m_value(reinterpret_cast<intptr_t>(rope) | 1) {}
     80
     81                Fiber(void* nonFiber) : m_value(reinterpret_cast<intptr_t>(nonFiber)) {}
    7782
    7883                void deref()
     
    110115                UString::Rep* string() { return reinterpret_cast<UString::Rep*>(m_value); }
    111116
     117                void* nonFiber() { return reinterpret_cast<void*>(m_value); }
    112118            private:
    113119                intptr_t m_value;
     
    246252        }
    247253
     254        JSString(JSGlobalData* globalData, const UString& value, JSStringFinalizerCallback finalizer, void* context)
     255            : JSCell(globalData->stringStructure.get())
     256            , m_stringLength(value.size())
     257            , m_value(value)
     258            , m_ropeLength(0)
     259        {
     260            // nasty hack because we can't union non-POD types
     261            m_fibers[0] = reinterpret_cast<void*>(finalizer);
     262            m_fibers[1] = context;
     263            Heap::heap(this)->reportExtraMemoryCost(value.cost());
     264        }
     265
    248266        ~JSString()
    249267        {
     
    251269            for (unsigned i = 0; i < m_ropeLength; ++i)
    252270                m_fibers[i].deref();
     271
     272            if (!m_ropeLength && m_fibers[0].nonFiber()) {
     273                JSStringFinalizerCallback finalizer = reinterpret_cast<JSStringFinalizerCallback>(m_fibers[0].nonFiber());
     274                finalizer(this, m_fibers[1].nonFiber());
     275            }
    253276        }
    254277
     
    348371        friend JSValue jsString(ExecState* exec, Register* strings, unsigned count);
    349372        friend JSValue jsString(ExecState* exec, JSValue thisValue, const ArgList& args);
     373        friend JSString* jsStringWithFinalizer(ExecState*, const UString&, JSStringFinalizerCallback callback, void* context);
    350374    };
    351375
     
    420444        }
    421445        return fixupVPtr(globalData, new (globalData) JSString(globalData, s));
     446    }
     447
     448    inline JSString* jsStringWithFinalizer(ExecState* exec, const UString& s, JSStringFinalizerCallback callback, void* context)
     449    {
     450        ASSERT(s.size() && (s.size() > 1 || s.data()[0] > 0xFF));
     451        JSGlobalData* globalData = &exec->globalData();
     452        return fixupVPtr(globalData, new (globalData) JSString(globalData, s, callback, context));
    422453    }
    423454
Note: See TracChangeset for help on using the changeset viewer.