Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: aeefbc27b80ad1c5c8ce432931b3b0da211b7ed6
      
https://github.com/WebKit/WebKit/commit/aeefbc27b80ad1c5c8ce432931b3b0da211b7ed6
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-07-14 (Tue, 14 Jul 2026)

  Changed paths:
    A JSTests/modules/dynamic-import-loaded-modules-cache.js
    A JSTests/modules/dynamic-import-loaded-modules-cache/leaf.js
    A JSTests/modules/dynamic-import-loaded-modules-cache/re-importer.js
    M Source/JavaScriptCore/runtime/JSModuleLoader.cpp

  Log Message:
  -----------
  [JSC] Skip redundant `resolve()` in `HostLoadImportedModule` for repeat 
dynamic imports
https://bugs.webkit.org/show_bug.cgi?id=313564

Reviewed by Yusuke Suzuki.

A warm dynamic import() (same specifier from the same referrer) currently
re-runs the host's moduleLoaderResolve hook even though the result is
already known. The hook can be expensive depending on the embedder, and
the spec already provides the cache to avoid it: HostLoadImportedModule
[1] is required to be idempotent for the same (referrer, moduleRequest)
pair, and FinishLoadingImportedModule [2] populates
referrer.[[LoadedModules]] for that purpose. InnerModuleLoading already
consults that cache before calling the host hook, but the top-level
loadModule() path used by dynamic import() does not.

Consult referrer.[[LoadedModules]] (the module's, or the Realm's
m_loadedModules) at the top of hostLoadImportedModule and short-circuit
to FinishLoadingImportedModule with the cached record on hit, returning
the existing registry entry's loadPromise. [[LoadedModules]] is populated
only on normal completion, so fetch / resolution failures fall through to
the existing slow path unchanged. Per the idempotency requirement, this
is unobservable.

In a local microbenchmark of 100,000 warm dynamic imports of one cached
module, per-import time drops from ~28 us to ~0.68 us. Cold loads are
unaffected since [[LoadedModules]] is empty on first call.

[1]: https://tc39.es/ecma262/#sec-HostLoadImportedModule
[2]: https://tc39.es/ecma262/#sec-FinishLoadingImportedModule

Tests: JSTests/modules/dynamic-import-loaded-modules-cache.js
       JSTests/modules/dynamic-import-loaded-modules-cache/leaf.js
       JSTests/modules/dynamic-import-loaded-modules-cache/re-importer.js

* JSTests/modules/dynamic-import-loaded-modules-cache.js: Added.
* JSTests/modules/dynamic-import-loaded-modules-cache/leaf.js: Added.
* JSTests/modules/dynamic-import-loaded-modules-cache/re-importer.js: Added.
* Source/JavaScriptCore/runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::hostLoadImportedModule):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to