GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing github.com — Move ESM loaders off-thread by JakobJingleheimer · Pull Request #44710 · nodejs/node Conversation
|
|
Review requested:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
2265b79 to
ce94ba6
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Does each worker thread get its own loader thread? E.g. if an app launches 2x worker threads, there will be 6x threads total: one main, 2x worker, 3x loader? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The current design puts all loaders in the same worker thread (eg there are a total of 2 threads: the main and the worker). Internal things are handled via the main thread; userland things are handled by the worker thread. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think that's slightly different than what I'm asking about. If a node app uses the worker threads API to launch worker threads, does each get its own loader thread? (where each loader thread may have one or more loaders running within it) Not does each loader get a thread, but does each user thread get a loader thread. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think the current state (before this PR) is that loaders always execute in the main thread, even if they’re “for” user code that is in a worker thread. So I would think that after this PR, loaders would run inside their worker thread, regardless of whether they’re customizing main or worker thread user code. So in other words, for an app using custom loaders where user code that spawns three workers, there are five threads total: main, loaders, and the three workers spawned by the user code. This is just my guess, others can please correct me if I’m mistaken. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't know how it's implemented but I would expect that each Node.js thread (main and workers) has its own separate loaders thread, at least for two reasons:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
First pass this seems fine but likely should investigate a thread per
loader URL/some key. Having it per thread they instrument would be more
costly if you spawn/tear down threads.
…On Tue, Sep 27, 2022, 1:24 PM Michaël Zasso ***@***.***> wrote:
I don't know how it's implemented but I would expect that each Node.js
thread (main and workers) has its own separate loaders thread, at least for
two reasons:
- Worker threads are supposed to be as isolated as possible from the
main thread and from each other
- You can spawn a worker thread with a different set of --loader flags.
—
Reply to this email directly, view it on GitHub
<#44710 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABZJI7YII3ZMWWAGIMOC6LWAM3WJANCNFSM6AAAAAAQPNEM7E>
.
You are receiving this because you are on a team that was mentioned.Message
ID: ***@***.***>
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What remains to be done? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Something in this implementation is causing node to hang on startup. We suspect it's some kind of circular dependency, and the subsequent dependency smacks into the Atomics lock (preventing the rest of the flow to complete, which would release the initial lock). I think this circular dep is between ESMLoader and Worker (it's rather difficult to troubleshoot as output is swallowed). There is a working PoC, so we know this works in principle (and that the Atomics otherwise behave appropriately, so the problem lies with integrating it into node). This was on hold whilst I was on holiday. I'm working on it today and tomorrow (but will be away on a business trip next week). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I found the circular dep:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Gah, it wasn't a circular dependency 🤦♂️ it was setting which caused the worker to spawn with nothing in it. (I shouldn't have copied it over from the previous attempt at off-threading, which was later hard-coding the I'm not sure if the internal worker should go through the There is (now was) a circular dependency issue after the empty worker issue is addressed in that's now fixed too.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 4667b07 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@JakobJingleheimer @aduh95 Oh, shit. This is merged? 😅 What version will it appear in? I want to check the testdouble loader to see if my changes to support off-thread loaders work. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@giltayar it will (hopefully) land on v20, see #47381 (comment) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
kudos to everyone involved! This was a mammoth task! 7 months and 100+ commits 😳🙏! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I'm so glad to see this land! 😻 I maintain a test suite for interoperable path resolution1, and I'm able to confirm that 4667b07 is compatible with browsers for synchronous Footnotes |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What is the recommended way to pass data from the main thread to a loader? Thanks in advance for any reply |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I see it is documented here (sorry for bothering) https://nodejs.org/api/esm.html#globalpreload I'll play around with this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We are unable to access the app path with ESM loaders being off threaded in v20 easily. See nodejs/help#4190 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looks like loaders no longer have access to process.argv |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Correct; that is how worker threads work. There is a dedicated issue for this as well as a proposal to address (which is already linked). I'm locking this as most of the recent comments are telling us the sky is blue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It looks like this should be marked as a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Marking it as semver-major would be wrong I think, because it's an experimental API, but it could be labelled as |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
esm, loader: move to own thread
There was an error while loading. Please reload this page.