Title: [289177] trunk/Source/_javascript_Core
Revision
289177
Author
[email protected]
Date
2022-02-06 12:37:53 -0800 (Sun, 06 Feb 2022)

Log Message

Cache the most recent AtomString produced by JSString::toIdentifier
https://bugs.webkit.org/show_bug.cgi?id=236124

Reviewed by Yusuke Suzuki.

JSString::toIdentifier does not store the result of atomizing its string
value, except when it is a rope. We can often end up atomizing the same
JSString a number of times.

This patch caches the last atomized string produced from
JSString::toIdentifier in a given VM. From local testing, this is a 0.5%
Speedometer2 improvement on an M1 MacBook Air, although surprisingly is
neutral on a recent Intel MacBook Pro.

* runtime/JSString.h:
(JSC::JSRopeString::toIdentifier const):
(JSC::JSString::toIdentifier const):
* runtime/VM.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (289176 => 289177)


--- trunk/Source/_javascript_Core/ChangeLog	2022-02-06 20:25:30 UTC (rev 289176)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-02-06 20:37:53 UTC (rev 289177)
@@ -1,3 +1,24 @@
+2022-02-06  Cameron McCormack  <[email protected]>
+
+        Cache the most recent AtomString produced by JSString::toIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=236124
+
+        Reviewed by Yusuke Suzuki.
+
+        JSString::toIdentifier does not store the result of atomizing its string
+        value, except when it is a rope. We can often end up atomizing the same
+        JSString a number of times.
+
+        This patch caches the last atomized string produced from
+        JSString::toIdentifier in a given VM. From local testing, this is a 0.5%
+        Speedometer2 improvement on an M1 MacBook Air, although surprisingly is
+        neutral on a recent Intel MacBook Pro.
+
+        * runtime/JSString.h:
+        (JSC::JSRopeString::toIdentifier const):
+        (JSC::JSString::toIdentifier const):
+        * runtime/VM.h:
+
 2022-02-06  David Kilzer  <[email protected]>
 
         [WASM] Fix clang tidy bugprone-move-forwarding-reference static analyzer warnings in WasmLLIntGenerator.cpp

Modified: trunk/Source/_javascript_Core/runtime/JSString.h (289176 => 289177)


--- trunk/Source/_javascript_Core/runtime/JSString.h	2022-02-06 20:25:30 UTC (rev 289176)
+++ trunk/Source/_javascript_Core/runtime/JSString.h	2022-02-06 20:37:53 UTC (rev 289177)
@@ -602,6 +602,7 @@
     JS_EXPORT_PRIVATE RefPtr<AtomStringImpl> resolveRopeToExistingAtomString(JSGlobalObject*) const;
     template<typename CharacterType> NEVER_INLINE void resolveRopeSlowCase(CharacterType*) const;
     template<typename CharacterType> void resolveRopeInternalNoSubstring(CharacterType*) const;
+    Identifier toIdentifier(JSGlobalObject*) const;
     void outOfMemory(JSGlobalObject* nullOrGlobalObjectForOOM) const;
     void resolveRopeInternal8(LChar*) const;
     void resolveRopeInternal16(UChar*) const;
@@ -759,15 +760,31 @@
     return JSString::create(vm, s.releaseImpl().releaseNonNull());
 }
 
-ALWAYS_INLINE Identifier JSString::toIdentifier(JSGlobalObject* globalObject) const
+ALWAYS_INLINE Identifier JSRopeString::toIdentifier(JSGlobalObject* globalObject) const
 {
     VM& vm = getVM(globalObject);
     auto scope = DECLARE_THROW_SCOPE(vm);
-    AtomString atomString = toAtomString(globalObject);
+    auto atomString = static_cast<const JSRopeString*>(this)->resolveRopeToAtomString(globalObject);
     RETURN_IF_EXCEPTION(scope, { });
     return Identifier::fromString(vm, atomString);
 }
 
+ALWAYS_INLINE Identifier JSString::toIdentifier(JSGlobalObject* globalObject) const
+{
+    if constexpr (validateDFGDoesGC)
+        vm().verifyCanGC();
+    if (isRope())
+        return static_cast<const JSRopeString*>(this)->toIdentifier(globalObject);
+    VM& vm = getVM(globalObject);
+    if (valueInternal().impl()->isAtom())
+        return Identifier::fromString(vm, Ref { *static_cast<AtomStringImpl*>(valueInternal().impl()) });
+    if (vm.lastAtomizedIdentifierStringImpl.ptr() != valueInternal().impl()) {
+        vm.lastAtomizedIdentifierStringImpl = *valueInternal().impl();
+        vm.lastAtomizedIdentifierAtomStringImpl = AtomStringImpl::add(valueInternal().impl()).releaseNonNull();
+    }
+    return Identifier::fromString(vm, Ref { vm.lastAtomizedIdentifierAtomStringImpl });
+}
+
 ALWAYS_INLINE AtomString JSString::toAtomString(JSGlobalObject* globalObject) const
 {
     if constexpr (validateDFGDoesGC)

Modified: trunk/Source/_javascript_Core/runtime/VM.h (289176 => 289177)


--- trunk/Source/_javascript_Core/runtime/VM.h	2022-02-06 20:25:30 UTC (rev 289176)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2022-02-06 20:37:53 UTC (rev 289177)
@@ -586,6 +586,8 @@
     NumericStrings numericStrings;
     std::unique_ptr<SimpleStats> machineCodeBytesPerBytecodeWordForBaselineJIT;
     Strong<JSString> lastCachedString;
+    Ref<StringImpl> lastAtomizedIdentifierStringImpl { *StringImpl::empty() };
+    Ref<AtomStringImpl> lastAtomizedIdentifierAtomStringImpl { *static_cast<AtomStringImpl*>(StringImpl::empty()) };
     JSONAtomStringCache jsonAtomStringCache;
 
     AtomStringTable* atomStringTable() const { return m_atomStringTable; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to