Skip to content

Commit

Permalink
Move the JSString cache from DOMWrapperWorld to VM.
Browse files Browse the repository at this point in the history
<https://webkit.org/b/131940>

Source/JavaScriptCore:
Reviewed by Geoff Garen.

* runtime/VM.h:

Source/WebCore:
Since there's no need for JSStrings to be world-specific, this patch
moves the string cache to JSC::VM. This makes jsStringWithCache()
a lot faster since it no longer has to jump through twenty-eleven
hoops to find the DOMWrapperWorld.

Reviewed by Geoff Garen.

* bindings/js/DOMWrapperWorld.cpp:
(WebCore::DOMWrapperWorld::clearWrappers):
* bindings/js/DOMWrapperWorld.h:
* bindings/js/JSDOMBinding.cpp:
(WebCore::jsStringWithCache):

Canonical link: https://commits.webkit.org/150025@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167605 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Apr 21, 2014
1 parent d650c16 commit 07c8968
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,12 @@
2014-04-21 Andreas Kling <akling@apple.com>

Move the JSString cache from DOMWrapperWorld to VM.
<https://webkit.org/b/131940>

Reviewed by Geoff Garen.

* runtime/VM.h:

2014-04-19 Filip Pizlo <fpizlo@apple.com>

Take block execution count estimates into account when voting double
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/VM.h
Expand Up @@ -295,6 +295,7 @@ namespace JSC {
NumericStrings numericStrings;
DateInstanceCache dateInstanceCache;
WTF::SimpleStats machineCodeBytesPerBytecodeWordForBaselineJIT;
WeakGCMap<StringImpl*, JSString, PtrHash<StringImpl*>> stringCache;

AtomicStringTable* atomicStringTable() const { return m_atomicStringTable; }

Expand Down
18 changes: 18 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,21 @@
2014-04-21 Andreas Kling <akling@apple.com>

Move the JSString cache from DOMWrapperWorld to VM.
<https://webkit.org/b/131940>

Since there's no need for JSStrings to be world-specific, this patch
moves the string cache to JSC::VM. This makes jsStringWithCache()
a lot faster since it no longer has to jump through twenty-eleven
hoops to find the DOMWrapperWorld.

Reviewed by Geoff Garen.

* bindings/js/DOMWrapperWorld.cpp:
(WebCore::DOMWrapperWorld::clearWrappers):
* bindings/js/DOMWrapperWorld.h:
* bindings/js/JSDOMBinding.cpp:
(WebCore::jsStringWithCache):

2014-04-21 David Hyatt <hyatt@apple.com>

[New Multicolumn] Column balancing is slow on float-multicol.html
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/bindings/js/DOMWrapperWorld.cpp
Expand Up @@ -53,7 +53,6 @@ DOMWrapperWorld::~DOMWrapperWorld()
void DOMWrapperWorld::clearWrappers()
{
m_wrappers.clear();
m_stringCache.clear();

// These items are created lazily.
while (!m_scriptControllersWithWindowShells.isEmpty())
Expand Down
3 changes: 0 additions & 3 deletions Source/WebCore/bindings/js/DOMWrapperWorld.h
Expand Up @@ -23,7 +23,6 @@
#define DOMWrapperWorld_h

#include "JSDOMGlobalObject.h"
#include <runtime/WeakGCMap.h>
#include <wtf/Forward.h>

namespace WebCore {
Expand All @@ -33,7 +32,6 @@ class JSDOMWrapper;
class ScriptController;

typedef HashMap<void*, JSC::Weak<JSC::JSObject>> DOMObjectWrapperMap;
typedef JSC::WeakGCMap<StringImpl*, JSC::JSString, PtrHash<StringImpl*>> JSStringCache;

class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
Expand All @@ -51,7 +49,6 @@ class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {

// FIXME: can we make this private?
DOMObjectWrapperMap m_wrappers;
JSStringCache m_stringCache;
HashMap<CSSValue*, void*> m_cssValueRoots;

bool isNormal() const { return m_isNormal; }
Expand Down
14 changes: 6 additions & 8 deletions Source/WebCore/bindings/js/JSDOMBinding.cpp
Expand Up @@ -65,22 +65,20 @@ const JSC::HashTable& getHashTableForGlobalData(VM& vm, const JSC::HashTable& st

JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s)
{
JSC::VM& vm = exec->vm();
StringImpl* stringImpl = s.impl();
if (!stringImpl || !stringImpl->length())
return jsEmptyString(exec);
return jsEmptyString(&vm);

if (stringImpl->length() == 1) {
UChar singleCharacter = (*stringImpl)[0u];
if (singleCharacter <= JSC::maxSingleCharacterString) {
JSC::VM* vm = &exec->vm();
return vm->smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
}
if (singleCharacter <= JSC::maxSingleCharacterString)
return vm.smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
}

JSStringCache& stringCache = currentWorld(exec).m_stringCache;
JSStringCache::AddResult addResult = stringCache.add(stringImpl, nullptr);
auto addResult = vm.stringCache.add(stringImpl, nullptr);
if (addResult.isNewEntry)
addResult.iterator->value = JSC::jsString(exec, String(stringImpl));
addResult.iterator->value = JSC::jsString(&vm, String(stringImpl));
return JSC::JSValue(addResult.iterator->value.get());
}

Expand Down

0 comments on commit 07c8968

Please sign in to comment.