Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: cae81af25d037bae6d8013d1be7cf946132ebf75
https://github.com/WebKit/WebKit/commit/cae81af25d037bae6d8013d1be7cf946132ebf75
Author: Sosuke Suzuki <[email protected]>
Date: 2026-06-28 (Sun, 28 Jun 2026)
Changed paths:
A JSTests/microbenchmarks/regexp-named-capture-exec.js
A JSTests/microbenchmarks/regexp-named-capture-replace.js
M Source/JavaScriptCore/runtime/RegExp.cpp
M Source/JavaScriptCore/runtime/RegExp.h
M Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp
M Source/JavaScriptCore/runtime/StringPrototype.cpp
Log Message:
-----------
[JSC] Cache named-capture "groups" Structure on RegExp
https://bugs.webkit.org/show_bug.cgi?id=317822
Reviewed by Yusuke Suzuki.
When a RegExp with named captures is exec'd, JSC builds the "groups"
object by starting from nullPrototypeObjectStructure and calling
putDirect for each capture name. On every exec this incurs, per group:
a hash lookup in m_namedGroupToParenIndices (redundant when there are no
duplicate names), an AtomString table intern via Identifier::fromString
(m_captureGroupNames held non-atomic Strings), and a Structure
transition table lookup. The shape of the groups object is fixed by the
pattern, so all of this is repeated work.
Store m_captureGroupNames as Vector<AtomString>, atomized once in
RegExp::finishCreation. Skip subpatternIdForGroupName when
m_numDuplicateNamedCaptureGroups is zero, since the answer is just the
loop index. Add RegExp::ensureGroupsStructure which lazily builds the
final {name0, name1, ...} Structure off nullPrototypeObjectStructure
and caches it in RareData (re-created when the realm differs, or
bypassed when the group count exceeds inline capacity). Callers then
allocate the groups object with that Structure directly and fill values
via putDirectOffset.
TipOfTree Patched
regexp-named-capture-exec 51.9984+-0.5105 ^ 28.5615+-0.1432
^ definitely 1.8206x faster
regexp-named-capture-replace 44.1759+-0.3794 ^ 29.3697+-0.3389
^ definitely 1.5041x faster
Tests: JSTests/microbenchmarks/regexp-named-capture-exec.js
JSTests/microbenchmarks/regexp-named-capture-replace.js
* JSTests/microbenchmarks/regexp-named-capture-exec.js: Added.
(test):
* JSTests/microbenchmarks/regexp-named-capture-replace.js: Added.
(test.replacer):
(test):
* Source/JavaScriptCore/runtime/RegExp.cpp:
(JSC::RegExp::finishCreation):
(JSC::RegExp::visitChildrenImpl):
(JSC::RegExp::ensureGroupsStructure):
* Source/JavaScriptCore/runtime/RegExp.h:
* Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp:
(JSC::createRegExpMatchesArrayWithGroupsOrIndices):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::replaceUsingRegExpSearch):
Canonical link: https://commits.webkit.org/315989@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications