Skip to content

[JSC] Walk star-export graph once when building a module namespace - #63795

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
sosukesuzuki:eng/get-module-namespace-bfs
Apr 30, 2026
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
sosukesuzuki:eng/get-module-namespace-bfs

Conversation

@sosukesuzuki

@sosukesuzuki sosukesuzuki commented Apr 28, 2026 •

Copy link
Copy Markdown
Member

66c577c

[JSC] Walk star-export graph once when building a module namespace
https://bugs.webkit.org/show_bug.cgi?id=313549

Reviewed by Yusuke Suzuki.

GetModuleNamespace [1] currently runs GetExportedNames followed by a
ResolveExport call per name. resolveExportImpl walks the star-export
graph independently for each name, so building a namespace for a deep
barrel module costs O(names * star-edges).

Walk the graph once instead, recording each name's unique Local /
Namespace binding. A name with exactly one such binding across the whole
star-reachable graph is provably Resolved regardless of resolveSet [2]
(resolveSet only turns paths into null, and merge(Resolved, null) =
Resolved). Names with an Indirect entry, or with two or more distinct
bindings, fall back to resolveExport(). The root module's own export
entries shadow star-reachable bindings (ResolveExport returns at step
4-6 before consulting star), so a star-side conflict for a name the root
already provides never goes to the slow path.

Add Resolution::isSameBinding() and reuse it in mergeToCurrentTop.

In a local microbenchmark importing a barrel of 9000 exported names
through ~1500 star edges, namespace creation drops from 331 ms to 19 ms
(~17x). For modules without `export *` the walk visits only the root, so
behavior and cost are unchanged.

[1]: https://tc39.es/ecma262/#sec-getmodulenamespace
[2]: https://tc39.es/ecma262/#sec-resolveexport

Tests: JSTests/modules/namespace-single-walk.js
       JSTests/modules/namespace-single-walk/conflict-only.js
       JSTests/modules/namespace-single-walk/cycle-a.js
       JSTests/modules/namespace-single-walk/cycle-b.js
       JSTests/modules/namespace-single-walk/leaf-a.js
       JSTests/modules/namespace-single-walk/leaf-b.js
       JSTests/modules/namespace-single-walk/mid-left.js
       JSTests/modules/namespace-single-walk/mid-right.js
       JSTests/modules/namespace-single-walk/root.js

* JSTests/modules/namespace-single-walk.js: Added.
* JSTests/modules/namespace-single-walk/conflict-only.js: Added.
* JSTests/modules/namespace-single-walk/cycle-a.js: Added.
* JSTests/modules/namespace-single-walk/cycle-b.js: Added.
* JSTests/modules/namespace-single-walk/leaf-a.js: Added.
* JSTests/modules/namespace-single-walk/leaf-b.js: Added.
* JSTests/modules/namespace-single-walk/mid-left.js: Added.
* JSTests/modules/namespace-single-walk/mid-right.js: Added.
* JSTests/modules/namespace-single-walk/root.js: Added.
* Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::resolveExportImpl):
(JSC::AbstractModuleRecord::getModuleNamespace):
(JSC::getExportedNames): Deleted.
* Source/JavaScriptCore/runtime/AbstractModuleRecord.h:
(JSC::AbstractModuleRecord::Resolution::isSameBinding const):

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

e21ac44

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

@sosukesuzuki sosukesuzuki self-assigned this Apr 28, 2026
@sosukesuzuki sosukesuzuki added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Apr 28, 2026
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #98164 (ddaae59)

❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 28, 2026
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

iOS Safer C++ Build #16516 (ddaae59)

❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@sosukesuzuki sosukesuzuki removed the merging-blocked Applied to prevent a change from being merged label Apr 28, 2026
@sosukesuzuki
sosukesuzuki force-pushed the eng/get-module-namespace-bfs branch from ddaae59 to 93faec5 Compare April 28, 2026 18:40
@heimskr

heimskr commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Thank you for your work on upstreaming this!

@sosukesuzuki
sosukesuzuki marked this pull request as ready for review April 28, 2026 23:20
@sosukesuzuki
sosukesuzuki requested a review from a team as a code owner April 28, 2026 23:20
ASSERT(cyclic->status() != CyclicModuleRecord::Status::New && cyclic->status() != CyclicModuleRecord::Status::Unlinked);
#endif

// http://www.ecma-international.org/ecma-262/6.0/#sec-getmodulenamespace

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

@sosukesuzuki
sosukesuzuki force-pushed the eng/get-module-namespace-bfs branch from 93faec5 to e21ac44 Compare April 29, 2026 16:23
@sosukesuzuki sosukesuzuki added merge-queue Applied to send a pull request to merge-queue and removed merge-queue Applied to send a pull request to merge-queue labels Apr 29, 2026
https://bugs.webkit.org/show_bug.cgi?id=313549

Reviewed by Yusuke Suzuki.

GetModuleNamespace [1] currently runs GetExportedNames followed by a
ResolveExport call per name. resolveExportImpl walks the star-export
graph independently for each name, so building a namespace for a deep
barrel module costs O(names * star-edges).

Walk the graph once instead, recording each name's unique Local /
Namespace binding. A name with exactly one such binding across the whole
star-reachable graph is provably Resolved regardless of resolveSet [2]
(resolveSet only turns paths into null, and merge(Resolved, null) =
Resolved). Names with an Indirect entry, or with two or more distinct
bindings, fall back to resolveExport(). The root module's own export
entries shadow star-reachable bindings (ResolveExport returns at step
4-6 before consulting star), so a star-side conflict for a name the root
already provides never goes to the slow path.

Add Resolution::isSameBinding() and reuse it in mergeToCurrentTop.

In a local microbenchmark importing a barrel of 9000 exported names
through ~1500 star edges, namespace creation drops from 331 ms to 19 ms
(~17x). For modules without `export *` the walk visits only the root, so
behavior and cost are unchanged.

[1]: https://tc39.es/ecma262/#sec-getmodulenamespace
[2]: https://tc39.es/ecma262/#sec-resolveexport

Tests: JSTests/modules/namespace-single-walk.js
       JSTests/modules/namespace-single-walk/conflict-only.js
       JSTests/modules/namespace-single-walk/cycle-a.js
       JSTests/modules/namespace-single-walk/cycle-b.js
       JSTests/modules/namespace-single-walk/leaf-a.js
       JSTests/modules/namespace-single-walk/leaf-b.js
       JSTests/modules/namespace-single-walk/mid-left.js
       JSTests/modules/namespace-single-walk/mid-right.js
       JSTests/modules/namespace-single-walk/root.js

* JSTests/modules/namespace-single-walk.js: Added.
* JSTests/modules/namespace-single-walk/conflict-only.js: Added.
* JSTests/modules/namespace-single-walk/cycle-a.js: Added.
* JSTests/modules/namespace-single-walk/cycle-b.js: Added.
* JSTests/modules/namespace-single-walk/leaf-a.js: Added.
* JSTests/modules/namespace-single-walk/leaf-b.js: Added.
* JSTests/modules/namespace-single-walk/mid-left.js: Added.
* JSTests/modules/namespace-single-walk/mid-right.js: Added.
* JSTests/modules/namespace-single-walk/root.js: Added.
* Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::resolveExportImpl):
(JSC::AbstractModuleRecord::getModuleNamespace):
(JSC::getExportedNames): Deleted.
* Source/JavaScriptCore/runtime/AbstractModuleRecord.h:
(JSC::AbstractModuleRecord::Resolution::isSameBinding const):

Canonical link: https://commits.webkit.org/312370@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/get-module-namespace-bfs branch from e21ac44 to 66c577c Compare April 30, 2026 16:27
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 312370@main (66c577c): https://commits.webkit.org/312370@main

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

@webkit-commit-queue
webkit-commit-queue merged commit 66c577c into WebKit:main Apr 30, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 30, 2026
Jarred-Sumner added a commit to oven-sh/WebKit that referenced this pull request Apr 30, 2026
…rop our RtlDllShutdownInProgress decl

e9072ad adds pas_process_is_shutting_down() (RtlDllShutdownInProgress
via GetProcAddress) and uses it in TLC destructor + WTF::Thread::didExit.
Subsumes our direct RtlDllShutdownInProgress guard; dropped the decl +
ntdll pragma from pas_thread.h.

AbstractModuleRecord: upstream landed the same single-pass star-export
walk (Sosuke WebKit#63795); replaced our equivalent with the canonical version,
keeping our shouldPreventExtensions parameter and BUN m_isTypeScript guard.

Kept: is_exiting flag, pas_thread_suspender plumbing, asymmetric
decommit_allocator_range (is_symmetric=false).
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.

6 participants