Skip to content

esm: avoid dictionary-mode objects in import() - #67554

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:esm-import-fast-objects
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:esm-import-fast-objects

Conversation

@mcollina

Copy link
Copy Markdown
Member

Import attributes were created in C++ with v8::Object::New() and a null
prototype, once per module request and once per import() call. Every
import() call also created a { __proto__: null } diagnostics_channel
context, which was discarded when module.import had no subscribers. V8
creates all of these in dictionary mode.

Build the attributes from an ordinary object with its prototype set to null,
and only create the trace context when there are subscribers. The attributes
are still frozen with a null prototype.

This is independent of #67552, and the two
merge cleanly.

                                                                       confidence improvement accuracy (*)   (**)  (***)
esm/esm-loader-import.js specifier='./relative-existing.js' n=10000           ***      7.24 %       ±1.13% ±1.50% ±1.96%
esm/esm-loader-import.js specifier='./relative-nonexistent.js' n=10000        ***      1.98 %       ±1.02% ±1.36% ±1.77%
esm/esm-loader-import.js specifier='data:text/javascript,{i}' n=10000                  1.27 %       ±1.82% ±2.42% ±3.16%
esm/esm-loader-import.js specifier='node:os' n=10000                          ***      7.83 %       ±1.36% ±1.81% ±2.36%
esm/esm-loader-import.js specifier='node:prefixed-nonexistent' n=10000        ***      7.27 %       ±1.49% ±1.99% ±2.59%

Refs: #67552


AI Generated.

Import attributes were created in C++ with v8::Object::New() and a
null prototype, once per module request and once per import() call.
Every import() call also created a `{ __proto__: null }`
diagnostics_channel context, which was discarded when module.import
had no subscribers. V8 creates all of these in dictionary mode.

Build the attributes from an ordinary object with its prototype set to
null, and only create the trace context when there are subscribers.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Nov 17, 2026

@gurgunday gurgunday left a comment

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.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 17, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecas

Copy link
Copy Markdown
Member

V8 has optimized this kind of objects in https://chromium-review.googlesource.com/c/v8/v8/+/8476491 with flag --fast-null-proto-literals (landed yesterday, expected to be included in m160).

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.67%. Comparing base (6a536f9) to head (f4e2267).
⚠️ Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67554      +/-   ##
==========================================
- Coverage   90.68%   90.67%   -0.01%     
==========================================
  Files         800      800              
  Lines      280556   281000     +444     
  Branches    54179    54293     +114     
==========================================
+ Hits       254412   254795     +383     
- Misses      16262    16299      +37     
- Partials     9882     9906      +24     
Files with missing lines Coverage Δ
lib/internal/modules/esm/loader.js 99.56% <100.00%> (+<0.01%) ⬆️
src/module_wrap.cc 74.33% <100.00%> (-0.08%) ⬇️

... and 47 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue PRs queued for automated landing through the Commit Queue. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants