[JSC] Add Map / Set fast iteration#63622
Merged
webkit-commit-queue merged 1 commit intoApr 27, 2026
Merged
Conversation
Collaborator
|
EWS run on previous version of this PR (hash 4e91010) Details
|
4e91010 to
8a9874d
Compare
Collaborator
|
EWS run on previous version of this PR (hash 8a9874d) Details
|
8a9874d to
74bcc28
Compare
Collaborator
|
EWS run on previous version of this PR (hash 74bcc28) Details |
74bcc28 to
a4269d5
Compare
Collaborator
|
EWS run on current version of this PR (hash a4269d5) Details
|
hyjorc1
approved these changes
Apr 27, 2026
https://bugs.webkit.org/show_bug.cgi?id=313340 rdar://175613242 Reviewed by Yijia Huang. Previously our iterator_open / iterator_next supports JSArray. This patch extends this fast iteration protocol to JSMap and JSSet. 1. LLInt / Baseline JIT should just simply add JSMap and JSMapIterator / JSSet and JSSetIterator iteration code. We extend IterationMode to have FastMap and FastSet. We also make constructArrayPair always using Contiguous (or Slow ArrayStorage when have-a-bad-time happens) to avoid frequent speculation failures when we inline them in DFG / FTL. 2. In DFG ByteCodeParser, we support JSMap / JSSet in iterator_open / iterator_next DFG nodes emission. One of the most subtle thing is OSR exit: MapIteratorNext changes the iterator, so after that, we cannot do OSR exit except for throwing an error, otherwise, OSR exit will advance the iterator again. We carefully emit DFG nodes which never does normal OSR exits, so this is fine. ToT Patched for-of-map-entries-small 7.3828+-0.1328 ^ 6.4153+-0.1580 ^ definitely 1.1508x faster set-for-of 1.3589+-0.0724 ^ 0.6633+-0.0403 ^ definitely 2.0486x faster for-of-set-values 2.4183+-0.0569 ^ 1.7421+-0.1980 ^ definitely 1.3881x faster for-of-map-entries 6.9321+-0.1456 ^ 5.7206+-0.1448 ^ definitely 1.2118x faster map-for-of 1.8342+-0.0780 ^ 1.1539+-0.0725 ^ definitely 1.5896x faster for-of-set-values-small 2.5314+-0.0253 ^ 1.9055+-0.0841 ^ definitely 1.3285x faster Tests: JSTests/microbenchmarks/for-of-map-entries-small.js JSTests/microbenchmarks/for-of-map-entries.js JSTests/microbenchmarks/for-of-set-values-small.js JSTests/microbenchmarks/for-of-set-values.js JSTests/stress/iterator-dfg-fast-path-bad-time.js JSTests/stress/iterator-dfg-fast-path-mixed-modes.js JSTests/stress/iterator-dfg-fast-path-no-generic.js * JSTests/microbenchmarks/for-of-map-entries-small.js: Added. (test): * JSTests/microbenchmarks/for-of-map-entries.js: Added. (test): * JSTests/microbenchmarks/for-of-set-values-small.js: Added. * JSTests/microbenchmarks/for-of-set-values.js: Added. * JSTests/stress/iterator-dfg-fast-path-bad-time.js: Added. (shouldBe): (sumMapEntries): (sumSetValues): (set add): (set Object): (set get for): * JSTests/stress/iterator-dfg-fast-path-mixed-modes.js: Added. (shouldBe): (sumIterable): (makeGeneric): * JSTests/stress/iterator-dfg-fast-path-no-generic.js: Added. (shouldBe): (sumAny): (runArrayMap): (runArraySet.sumArrOrSet): (runArraySet): (runAllFastNoGeneric): * Source/JavaScriptCore/builtins/MapIteratorPrototype.js: (next): * Source/JavaScriptCore/builtins/SetIteratorPrototype.js: (next): * Source/JavaScriptCore/bytecode/IterationModeMetadata.h: * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): (JSC::DFG::ByteCodeParser::handleIteratorOpen): (JSC::DFG::ByteCodeParser::handleIteratorNext): * Source/JavaScriptCore/dfg/DFGMayExit.cpp: * Source/JavaScriptCore/jit/JITOperations.cpp: (JSC::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/jit/JITOperations.h: * Source/JavaScriptCore/runtime/CommonSlowPaths.cpp: (JSC::iteratorOpenTryFastImpl): (JSC::iteratorNextTryFastImpl): * Source/JavaScriptCore/runtime/IteratorOperations.cpp: (JSC::getIterationMode): * Source/JavaScriptCore/runtime/JSArray.cpp: (JSC::constructArrayPair): * Source/JavaScriptCore/runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): (JSC::JSGlobalObject::visitChildrenImpl): * Source/JavaScriptCore/runtime/JSGlobalObject.h: * Source/JavaScriptCore/runtime/MapPrototype.cpp: (JSC::MapPrototype::finishCreation): * Source/JavaScriptCore/runtime/MapPrototype.h: * Source/JavaScriptCore/runtime/SetPrototype.cpp: (JSC::SetPrototype::finishCreation): * Source/JavaScriptCore/runtime/SetPrototype.h: Canonical link: https://commits.webkit.org/312127@main
a4269d5 to
4337048
Compare
Collaborator
|
Committed 312127@main (4337048): https://commits.webkit.org/312127@main Reviewed commits have been landed. Closing PR #63622 and removing active labels. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
4337048
a4269d5