Skip to content

[JSC] Add RegExpSubstringGlobalAtomCache - #34805

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
hyjorc1:eng/JSC-Add-RegExpSubstringGlobalAtomCache
Oct 8, 2024
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
hyjorc1:eng/JSC-Add-RegExpSubstringGlobalAtomCache

Conversation

@hyjorc1

@hyjorc1 hyjorc1 commented Oct 7, 2024 •

Copy link
Copy Markdown
Contributor

4321993

[JSC] Add RegExpSubstringGlobalAtomCache
https://bugs.webkit.org/show_bug.cgi?id=281012
rdar://137459855

Reviewed by Yusuke Suzuki.

Inspired by [1], this update adds a caching mechanism to optimize
repeated matching of global atomic regular expressions on growing
substrings. By caching results, we avoid redundant work and improve
performance, particularly in scenarios where the same RegExp is applied
to overlapping or incrementally growing substrings.

MicroBenchmark Result with `--inner 10 --outer 20`:

                                       before                    after

substring-match-global-atom        3.1816+-0.0123     ^      2.4063+-0.0082        ^ definitely 1.3222x faster

[1] https://chromium-review.googlesource.com/c/v8/v8/+/5886727

* JSTests/microbenchmarks/substring-match-global-atom.js: Added.
(test):
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/runtime/JSString.h:
(JSC::JSString::asRope):
* Source/JavaScriptCore/runtime/RegExp.cpp:
(JSC::RegExp::finishCreation):
(JSC::RegExp::byteCodeCompileIfNecessary):
(JSC::RegExp::compile):
(JSC::RegExp::compileMatchOnly):
(JSC::RegExp::deleteCode):
* Source/JavaScriptCore/runtime/RegExp.h:
* Source/JavaScriptCore/runtime/RegExpGlobalData.h:
(JSC::RegExpGlobalData::substringGlobalAtomCache):
* Source/JavaScriptCore/runtime/RegExpObject.cpp:
(JSC::RegExpObject::matchGlobal):
* Source/JavaScriptCore/runtime/RegExpSubstringGlobalAtomCache.cpp: Added.
(JSC::RegExpSubstringGlobalAtomCache::visitAggregateImpl):
(JSC::RegExpSubstringGlobalAtomCache::hasValidPattern):
(JSC::RegExpSubstringGlobalAtomCache::tryGet):
(JSC::RegExpSubstringGlobalAtomCache::record):
(JSC::RegExpSubstringGlobalAtomCache::collectMatches):
* Source/JavaScriptCore/runtime/RegExpSubstringGlobalAtomCache.h: Copied from Source/JavaScriptCore/runtime/RegExpGlobalData.h.
(JSC::RegExpSubstringGlobalAtomCache::lastRegExp):
* Source/JavaScriptCore/yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::extractAtom):
(JSC::Yarr::YarrPattern::compile):
* Source/JavaScriptCore/yarr/YarrPattern.h:

Canonical link: https://commits.webkit.org/284859@main

a570b8f

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac   🛠 wpe   🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug   🧪 wpe-wk2   🧪 win-tests
✅ 🧪 webkitperl   🧪 ios-wk2 ✅ 🧪 api-mac   🧪 api-wpe
  🧪 ios-wk2-wpt ✅ 🧪 mac-wk1   🛠 wpe-cairo
  🛠 🧪 jsc   🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision   🧪 mac-AS-debug-wk2   🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress   🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2   🧪 mac-intel-wk2 ✅ 🛠 jsc-armv7
✅ 🛠 tv ✅ 🧪 jsc-armv7-tests
  🛠 tv-sim
  🛠 watch
  🛠 watch-sim

@hyjorc1 hyjorc1 self-assigned this Oct 7, 2024
@hyjorc1 hyjorc1 added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Oct 7, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 7, 2024
@hyjorc1 hyjorc1 removed the merging-blocked Applied to prevent a change from being merged label Oct 8, 2024
@hyjorc1
hyjorc1 force-pushed the eng/JSC-Add-RegExpSubstringGlobalAtomCache branch from 5afe934 to 405180e Compare October 8, 2024 07:50
@hyjorc1
hyjorc1 marked this pull request as ready for review October 8, 2024 16:40
@hyjorc1
hyjorc1 requested a review from a team as a code owner October 8, 2024 16:40

@Constellation Constellation left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add a link to V8 change too we get inspired from in the commit message.

Comment thread Source/JavaScriptCore/runtime/RegExpSubstringGlobalAtomCache.cpp Outdated
@hyjorc1
hyjorc1 force-pushed the eng/JSC-Add-RegExpSubstringGlobalAtomCache branch from 405180e to a570b8f Compare October 8, 2024 22:11
@hyjorc1

hyjorc1 commented Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

You need to call visitAggregate of this newly added cache.

Done.

@hyjorc1 hyjorc1 added the merge-queue Applied to send a pull request to merge-queue label Oct 8, 2024
https://bugs.webkit.org/show_bug.cgi?id=281012
rdar://137459855

Reviewed by Yusuke Suzuki.

Inspired by [1], this update adds a caching mechanism to optimize
repeated matching of global atomic regular expressions on growing
substrings. By caching results, we avoid redundant work and improve
performance, particularly in scenarios where the same RegExp is applied
to overlapping or incrementally growing substrings.

MicroBenchmark Result with `--inner 10 --outer 20`:

                                       before                    after

substring-match-global-atom        3.1816+-0.0123     ^      2.4063+-0.0082        ^ definitely 1.3222x faster

[1] https://chromium-review.googlesource.com/c/v8/v8/+/5886727

* JSTests/microbenchmarks/substring-match-global-atom.js: Added.
(test):
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/runtime/JSString.h:
(JSC::JSString::asRope):
* Source/JavaScriptCore/runtime/RegExp.cpp:
(JSC::RegExp::finishCreation):
(JSC::RegExp::byteCodeCompileIfNecessary):
(JSC::RegExp::compile):
(JSC::RegExp::compileMatchOnly):
(JSC::RegExp::deleteCode):
* Source/JavaScriptCore/runtime/RegExp.h:
* Source/JavaScriptCore/runtime/RegExpGlobalData.h:
(JSC::RegExpGlobalData::substringGlobalAtomCache):
* Source/JavaScriptCore/runtime/RegExpObject.cpp:
(JSC::RegExpObject::matchGlobal):
* Source/JavaScriptCore/runtime/RegExpSubstringGlobalAtomCache.cpp: Added.
(JSC::RegExpSubstringGlobalAtomCache::visitAggregateImpl):
(JSC::RegExpSubstringGlobalAtomCache::hasValidPattern):
(JSC::RegExpSubstringGlobalAtomCache::tryGet):
(JSC::RegExpSubstringGlobalAtomCache::record):
(JSC::RegExpSubstringGlobalAtomCache::collectMatches):
* Source/JavaScriptCore/runtime/RegExpSubstringGlobalAtomCache.h: Copied from Source/JavaScriptCore/runtime/RegExpGlobalData.h.
(JSC::RegExpSubstringGlobalAtomCache::lastRegExp):
* Source/JavaScriptCore/yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::extractAtom):
(JSC::Yarr::YarrPattern::compile):
* Source/JavaScriptCore/yarr/YarrPattern.h:

Canonical link: https://commits.webkit.org/284859@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/JSC-Add-RegExpSubstringGlobalAtomCache branch from a570b8f to 4321993 Compare October 8, 2024 23:23
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 284859@main (4321993): https://commits.webkit.org/284859@main

Reviewed commits have been landed. Closing PR #34805 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit 4321993 into WebKit:main Oct 8, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants