Skip to content

[JSC] Add OwnStructureMode fast path to for-in sites that saw multiple modes - #79357

Open
sosukesuzuki wants to merge 1 commit into
WebKit:mainfrom
sosukesuzuki:eng/JSC-Add-OwnStructureMode-fast-path-to-for-in-sites-that-saw-multiple-modes
Open

sosukesuzuki wants to merge 1 commit into
WebKit:mainfrom
sosukesuzuki:eng/JSC-Add-OwnStructureMode-fast-path-to-for-in-sites-that-saw-multiple-modes

Conversation

@sosukesuzuki

@sosukesuzuki sosukesuzuki commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

c99bd33

[JSC] Add `OwnStructureMode` fast path to for-in sites that saw multiple modes
https://bugs.webkit.org/show_bug.cgi?id=329861

Reviewed by NOBODY (OOPS!).

When a for-in site has seen more than one enumeration mode, Baseline, DFG and FTL
call operationEnumeratorNextUpdateIndexAndMode for every key, even for objects that
can be enumerated in OwnStructureMode.

This patch adds a runtime check to such sites. If the enumerator starts with structure
properties, the base still has the enumerator's cached StructureID, and the next index
is still within the structure properties, we just increment the index. Otherwise we
call the operation as before. This is the same condition that
JSPropertyNameEnumerator::computeNext uses, and it is checked for every key, so changing
the structure in the middle of the loop is handled by the operation.

                                                            Baseline                  Patched

for-in-object-with-own-named-at-site-with-generic-mode
                                                       121.1571+-7.1595     ^     38.1534+-1.7732        ^ definitely 3.1755x faster

Tests: JSTests/microbenchmarks/for-in-object-with-own-named-at-site-with-generic-mode.js
       JSTests/stress/for-in-own-structure-mode-at-site-with-all-modes.js
       JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes-structure-change.js
       JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes.js

* JSTests/microbenchmarks/for-in-object-with-own-named-at-site-with-generic-mode.js: Added.
(sum):
* JSTests/stress/for-in-own-structure-mode-at-site-with-all-modes.js: Added.
(shouldBe):
(allModes):
(ownThenOthers):
* JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes-structure-change.js: Added.
(shouldBe):
(plain):
(withDeletedProperty):
(withInheritedProperties):
(deleteWhileEnumerating):
(addWhileEnumerating):
(addAndDeleteWhileEnumerating):
(hideWhileEnumerating):
* JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes.js: Added.
(shouldBe):
(ownAndGeneric):
(ownAndIndexed):
(ownAndThrowing):
(getOwnPropertyDescriptor):
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileEnumeratorNextUpdateIndexAndMode):
* Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileEnumeratorNextUpdateIndexAndMode):
* Source/JavaScriptCore/jit/JITPropertyAccess.cpp:
(JSC::JIT::emit_op_enumerator_next):

c99bd33

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-cmake-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-cmake-debug ✅ 🧪 jsc-wpe
✅ 🧪 jsc-x86-64 ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-cmake-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

…ple modes

https://bugs.webkit.org/show_bug.cgi?id=329861

Reviewed by NOBODY (OOPS!).

When a for-in site has seen more than one enumeration mode, Baseline, DFG and FTL
call operationEnumeratorNextUpdateIndexAndMode for every key, even for objects that
can be enumerated in OwnStructureMode.

This patch adds a runtime check to such sites. If the enumerator starts with structure
properties, the base still has the enumerator's cached StructureID, and the next index
is still within the structure properties, we just increment the index. Otherwise we
call the operation as before. This is the same condition that
JSPropertyNameEnumerator::computeNext uses, and it is checked for every key, so changing
the structure in the middle of the loop is handled by the operation.

                                                            Baseline                  Patched

for-in-object-with-own-named-at-site-with-generic-mode
                                                       121.1571+-7.1595     ^     38.1534+-1.7732        ^ definitely 3.1755x faster

Tests: JSTests/microbenchmarks/for-in-object-with-own-named-at-site-with-generic-mode.js
       JSTests/stress/for-in-own-structure-mode-at-site-with-all-modes.js
       JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes-structure-change.js
       JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes.js

* JSTests/microbenchmarks/for-in-object-with-own-named-at-site-with-generic-mode.js: Added.
(sum):
* JSTests/stress/for-in-own-structure-mode-at-site-with-all-modes.js: Added.
(shouldBe):
(allModes):
(ownThenOthers):
* JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes-structure-change.js: Added.
(shouldBe):
(plain):
(withDeletedProperty):
(withInheritedProperties):
(deleteWhileEnumerating):
(addWhileEnumerating):
(addAndDeleteWhileEnumerating):
(hideWhileEnumerating):
* JSTests/stress/for-in-own-structure-mode-at-site-with-multiple-modes.js: Added.
(shouldBe):
(ownAndGeneric):
(ownAndIndexed):
(ownAndThrowing):
(getOwnPropertyDescriptor):
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileEnumeratorNextUpdateIndexAndMode):
* Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileEnumeratorNextUpdateIndexAndMode):
* Source/JavaScriptCore/jit/JITPropertyAccess.cpp:
(JSC::JIT::emit_op_enumerator_next):
@sosukesuzuki sosukesuzuki self-assigned this Nov 2, 2026
@sosukesuzuki
sosukesuzuki requested a review from a team as a code owner November 2, 2026 20:52
@sosukesuzuki sosukesuzuki added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Nov 2, 2026
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.

2 participants