[webkit-changes] [WebKit/WebKit] e4568f: [JSC] Add StringSplitCache
Yusuke Suzuki
noreply at github.com
Wed May 31 12:36:37 PDT 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e4568fa804be7b5d0c9fd788a3885faf1e6d2284
https://github.com/WebKit/WebKit/commit/e4568fa804be7b5d0c9fd788a3885faf1e6d2284
Author: Yusuke Suzuki <ysuzuki at apple.com>
Date: 2023-05-31 (Wed, 31 May 2023)
Changed paths:
M Source/JavaScriptCore/CMakeLists.txt
M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
M Source/JavaScriptCore/heap/Heap.cpp
M Source/JavaScriptCore/runtime/ArgList.h
M Source/JavaScriptCore/runtime/StringPrototype.cpp
A Source/JavaScriptCore/runtime/StringSplitCache.h
A Source/JavaScriptCore/runtime/StringSplitCacheInlines.h
M Source/JavaScriptCore/runtime/VM.cpp
M Source/JavaScriptCore/runtime/VM.h
Log Message:
-----------
[JSC] Add StringSplitCache
https://bugs.webkit.org/show_bug.cgi?id=257530
rdar://problem/110053165
Reviewed by Justin Michaud.
This patch adds String#split cache, inspired from V8's string split cache.
It is common in the real world code that splitting a literal string with a literal
separator because of readability, and it can be done multiple times instead of doing it globally.
Instead of repeatedly splitting and re-generating strings again and again, we can safely cache the result.
This patch caches result as JSImmutableButterfly when the both subject and separator are atom strings.
In String#split operation, also, instead of generating substrings and extending butterfly, we just compute
offset of substrings. And then finally generating JSImmutableButterfly / JSArray with repeated substrings.
This avoids wasteful intermediate butterfly allocations.
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/heap/Heap.cpp:
(JSC::Heap::finalize):
* Source/JavaScriptCore/runtime/ArgList.h:
(JSC::ArgList::ArgList):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::splitStringByOneCharacterImpl):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/StringSplitCache.h: Added.
(JSC::StringSplitCache::clear):
* Source/JavaScriptCore/runtime/StringSplitCacheInlines.h: Added.
(JSC::StringSplitCache::get):
(JSC::StringSplitCache::set):
* Source/JavaScriptCore/runtime/VM.cpp:
(JSC::VM::VM):
* Source/JavaScriptCore/runtime/VM.h:
Canonical link: https://commits.webkit.org/264749@main
More information about the webkit-changes
mailing list