-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
esm: avoid import.meta
setup costs for unused properties
#57003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esm: avoid import.meta
setup costs for unused properties
#57003
Conversation
Review requested:
|
90d6aac
to
b3575a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, my personal time identity backed this out due to a lot of waffling and someone finally providing evidence against it -- #48740 (comment)
(Very easy to overlook that in all of the nonsense on that PR.)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #57003 +/- ##
==========================================
+ Coverage 89.13% 90.27% +1.14%
==========================================
Files 665 630 -35
Lines 193125 186189 -6936
Branches 37182 36474 -708
==========================================
- Hits 172136 168089 -4047
+ Misses 13734 10979 -2755
+ Partials 7255 7121 -134
🚀 New features to boost your workflow:
|
😆
It looks like the spec was misquoted. I'm not sure what Antoine was getting at with
Getters are not run right away—that's their whole point. |
They were in that specific implementation. But I was quite happy to stop churning on the detail. I am not against these being getters. I'm just linking the history. |
https://tc39.es/ecma262/#sec-meta-properties-runtime-semantics-evaluation The spec’s intention is very much that import.meta only contains data properties. It’s surely possible to use C++ to make an object that appears to have data properties but avoids paying the up front cost, but it wouldnt be possible in JS. As is, this change is observable to someone looking at property descriptors, and this i think needs to be semver major. |
I agree with Bradley in the other thread that I don't think the exact property descriptor is "part of the API" here but I don't feel strongly enough about it to say that it must be semver minor over major. |
It absolutely allows it - but the intention was for freezing and not for making getters, as i recall. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@ljharb as I recall it was for freezing from Agoric side of convo and altering proto from web vendor side (including a potential desire for accessors from proto). |
ah, I don't recall that second part. |
@ljharb they never shipped it and likely never will at this point |
an alternative that is still a data property and is lazy is to use https://v8.github.io/api/head/classv8_1_1Object.html#a918a985db244fdc1bde268741e840620 |
ed9b3cb
to
c3c12a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still consider this a breaking change, but LGTM
Ah, damn. Looks like it will miss 24.0.0; I was thinking it still might land for that and breaking/non-breaking would be a discussion we don't have to have 😅 (aside from backport). |
Doing it in C++ would make it nonbreaking, if that's preferred. |
Mmm, I was hoping/expecting that approach to tick all the boxes. But it seems a mixed bag, IMO leaning towards the less ideal. I was just planning to get this PR to a landable state so then we can decide A or B. To me, the approach in this PR is in the vicinity of breaking territory in that it may be observable. But, I'm thinking it won't actually be tangible (and thus won't actually break anything). |
I agree that breakage is unlikely, but semver doesn't deal in likelihoods :-) fwiw it seems perfectly fine to land this on 25+, and then convert it to C++ in a future PR, at which point both commits would be maximally backportable together. |
Commit Queue failed- Loading data for nodejs/node/pull/57003 ✔ Done loading data for nodejs/node/pull/57003 ----------------------------------- PR info ------------------------------------ Title esm: avoid `import.meta` setup costs for unused properties (#57003) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch JakobJingleheimer:esm/avoid-setup-costs-for-unused-importmeta-props -> nodejs:main Labels semver-major, esm, author ready, needs-ci, commit-queue-squash Commits 3 - esm: avoid `import.meta` setup costs for unused properties - !fixup: correct autocomplete of prop name - fixup!: add test case for re-assigning `dirname` & `filename` Committers 1 - Jacob Smith <[email protected]> PR-URL: https://github.com/nodejs/node/pull/57003 Reviewed-By: Jan Martin <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jordan Harband <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/57003 Reviewed-By: Jan Martin <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jordan Harband <[email protected]> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 11 Feb 2025 10:54:37 GMT ✔ Approvals: 3 ✔ - Jan Martin (@jkrems): https://github.com/nodejs/node/pull/57003#pullrequestreview-2785333954 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/57003#pullrequestreview-2610219287 ✔ - Jordan Harband (@ljharb): https://github.com/nodejs/node/pull/57003#pullrequestreview-2785323386 ✘ semver-major requires at least 2 TSC approvals ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-04-22T20:58:45Z: https://ci.nodejs.org/job/node-test-pull-request/66416/ - Querying data for job/node-test-pull-request/66416/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/14614621512 |
Ah, needs 2 TSC approvals, not just 1. |
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1694/
|
I don't know how to read that benchmark 😅 Could we also run CitGM? (I don't know how to trigger it) |
The benchmark shows a worst result than #57286 for |
Benchmark CI to include the results form #58056: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1710/
|
Superseded by #57286 |
Currently, the cost of deriving
import.meta.dirname
andimport.meta.filename
is paid up-front, regardless of whether they are actually used. This can instead be delayed until they are accessed, and then to avoid re-paying the cost, overwrite the getter with the derived value.