Title: [241237] trunk/Source
- Revision
- 241237
- Author
- [email protected]
- Date
- 2019-02-08 23:58:01 -0800 (Fri, 08 Feb 2019)
Log Message
[WTF] Use BufferInternal StringImpl if substring StringImpl takes more memory
https://bugs.webkit.org/show_bug.cgi?id=194469
Reviewed by Geoffrey Garen.
Source/_javascript_Core:
* runtime/JSString.h:
(JSC::jsSubstring):
Source/WTF:
Because pointer is large and aligned in 64bit in 64bit architecture, BufferSubstring StringImpl
implementation takes more memory than BufferInternal StringImpl implementation for small strings.
And BufferInternal StringImpl does not have a problem like, small substring StringImpl keeps super
large owner StringImpl. This patch calculates the required size of memory and selects the more efficient one.
* wtf/text/StringImpl.h:
(WTF::StringImpl::isSubString const):
(WTF::StringImpl::createSubstringSharingImpl):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (241236 => 241237)
--- trunk/Source/_javascript_Core/ChangeLog 2019-02-09 07:43:26 UTC (rev 241236)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-02-09 07:58:01 UTC (rev 241237)
@@ -1,5 +1,15 @@
2019-02-08 Yusuke Suzuki <[email protected]>
+ [WTF] Use BufferInternal StringImpl if substring StringImpl takes more memory
+ https://bugs.webkit.org/show_bug.cgi?id=194469
+
+ Reviewed by Geoffrey Garen.
+
+ * runtime/JSString.h:
+ (JSC::jsSubstring):
+
+2019-02-08 Yusuke Suzuki <[email protected]>
+
[JSC] CachedTypes should use jsString instead of JSString::create
https://bugs.webkit.org/show_bug.cgi?id=194471
Modified: trunk/Source/_javascript_Core/runtime/JSString.h (241236 => 241237)
--- trunk/Source/_javascript_Core/runtime/JSString.h 2019-02-09 07:43:26 UTC (rev 241236)
+++ trunk/Source/_javascript_Core/runtime/JSString.h 2019-02-09 07:58:01 UTC (rev 241237)
@@ -636,7 +636,10 @@
if (c <= maxSingleCharacterString)
return vm->smallStrings.singleCharacterString(c);
}
- return JSString::createHasOtherOwner(*vm, StringImpl::createSubstringSharingImpl(*s.impl(), offset, length));
+ auto impl = StringImpl::createSubstringSharingImpl(*s.impl(), offset, length);
+ if (impl->isSubString())
+ return JSString::createHasOtherOwner(*vm, WTFMove(impl));
+ return JSString::create(*vm, WTFMove(impl));
}
inline JSString* jsOwnedString(VM* vm, const String& s)
Modified: trunk/Source/WTF/ChangeLog (241236 => 241237)
--- trunk/Source/WTF/ChangeLog 2019-02-09 07:43:26 UTC (rev 241236)
+++ trunk/Source/WTF/ChangeLog 2019-02-09 07:58:01 UTC (rev 241237)
@@ -1,3 +1,19 @@
+2019-02-08 Yusuke Suzuki <[email protected]>
+
+ [WTF] Use BufferInternal StringImpl if substring StringImpl takes more memory
+ https://bugs.webkit.org/show_bug.cgi?id=194469
+
+ Reviewed by Geoffrey Garen.
+
+ Because pointer is large and aligned in 64bit in 64bit architecture, BufferSubstring StringImpl
+ implementation takes more memory than BufferInternal StringImpl implementation for small strings.
+ And BufferInternal StringImpl does not have a problem like, small substring StringImpl keeps super
+ large owner StringImpl. This patch calculates the required size of memory and selects the more efficient one.
+
+ * wtf/text/StringImpl.h:
+ (WTF::StringImpl::isSubString const):
+ (WTF::StringImpl::createSubstringSharingImpl):
+
2019-02-08 Alex Christensen <[email protected]>
Add SPI to use networking daemon instead of XPC service
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (241236 => 241237)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2019-02-09 07:43:26 UTC (rev 241236)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2019-02-09 07:58:01 UTC (rev 241237)
@@ -297,9 +297,7 @@
bool isExternal() const { return bufferOwnership() == BufferExternal; }
-#if STRING_STATS
bool isSubString() const { return bufferOwnership() == BufferSubstring; }
-#endif
static WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> utf8ForCharacters(const LChar* characters, unsigned length);
static WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode = LenientConversion);
@@ -937,10 +935,20 @@
if (!length)
return *empty();
+ // Coyping the thing would save more memory sometimes, largely due to the size of pointer.
+ size_t substringSize = allocationSize<StringImpl*>(1);
+ if (rep.is8Bit()) {
+ if (substringSize >= allocationSize<LChar>(length))
+ return create(rep.m_data8 + offset, length);
+ } else {
+ if (substringSize >= allocationSize<UChar>(length))
+ return create(rep.m_data16 + offset, length);
+ }
+
auto* ownerRep = ((rep.bufferOwnership() == BufferSubstring) ? rep.substringBuffer() : &rep);
// We allocate a buffer that contains both the StringImpl struct as well as the pointer to the owner string.
- auto* stringImpl = static_cast<StringImpl*>(fastMalloc(allocationSize<StringImpl*>(1)));
+ auto* stringImpl = static_cast<StringImpl*>(fastMalloc(substringSize));
if (rep.is8Bit())
return adoptRef(*new (NotNull, stringImpl) StringImpl(rep.m_data8 + offset, length, *ownerRep));
return adoptRef(*new (NotNull, stringImpl) StringImpl(rep.m_data16 + offset, length, *ownerRep));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes