镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

esm, loader: move to own thread #43658

Description

@JakobJingleheimer

What is the problem this feature will solve?

  • limit contamination
  • facilitate synchronous import.meta.resolve()

For the initial implementation, the same loaders thread will be used for all user-land threads. A subsequent enhancement may add a configuration option to the Worker constructor to spawn its own dedicated loaders thread.

What is the feature you are proposing to solve the problem?

Move loaders off-thread

What alternatives have you considered?

No response


Per direction from TSC

Following in the vein of babel: babel/babel#14025
And https://github.com/bmeck/using-node-workshop/tree/main/steps/6_async_and_blocking


  • notify package authors of change (please comment to be added if not already included—sorry I know only so many)
    • esmock
    • jest?
    • mocha (Gil Tayar)
    • ts-node (Andrew Bradley)
    • yarn (Maël Nison)

Activity

  1. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    loadersIssues and PRs related to ES module loaders.
    on Jul 2, 2022
  2. JakobJingleheimer commented on Jul 2, 2022

    @JakobJingleheimer
    MemberAuthor

    @bmeck @MylesBorins could either of you speak to the impetus for this?

  3. aduh95 commented on Jul 5, 2022

    @aduh95
    Contributor

    Related: #31229

  4. GeoffreyBooth commented on Jul 20, 2022

    @GeoffreyBooth
    Member

    @bmeck @MylesBorins could either of you speak to the impetus for this?

    Pros and cons here: nodejs/modules#351 (comment)

  5. cspotcode commented on Jul 20, 2022

    @cspotcode

    Can add to the list of package authors:
    esmock

    I wonder, does it make sense for the loaders team to have a thread somewhere which can be subscribed to for notifications of breaking changes? All relevant discussion can happen elsewhere, the thread would be like an RSS feed. Package maintainers can opt-in to notifications of breaking or potentially exciting/disruptive changes by subscribing to that thread.

    Might scale better than us hoping we know a comprehensive list of all loaders.

  6. JakobJingleheimer commented on Jul 20, 2022

    @JakobJingleheimer
    MemberAuthor

    Since Node.js doesn't maintain anything of the sort, that sounds like a better alternative to "surprise!". It's not full-proof, though.

  7. JakobJingleheimer commented on Sep 17, 2022

    @JakobJingleheimer
    MemberAuthor
  8. changed the title [-]esm, loaders: move to own thread[/-] [+]esm, loader: move to own thread[/+] on Sep 18, 2022
  9. loynoir commented on Oct 5, 2022

    @loynoir
  10. devkarlson commented on Oct 19, 2022

    @devkarlson
  11. 7 remaining items

  12. GeoffreyBooth commented on Oct 23, 2022

    @GeoffreyBooth
    Member

    There's also a potential benefit in moving non-custom loading off-thread as it would protect internals from prototype pollution (I think). That would argue that we should make this same refactor for CommonJS too.

  13. aduh95 commented on Oct 23, 2022

    @aduh95
    Contributor

    This is a significant blocker for me as Node.js is often used in environment that are constrained by memory. At the bare minimum we should investigate:

    1. how much more memory is needed?
    2. how much more latency this will add?
    3. can we avoid it, i.e. only move user-provided code off thread?
    4. will this memory cost disappear or will the thread be kept around?

    @mcollina I'm not convinced we can answer those questions before we have a fully working implementation; without data, we can only make assumptions, and I wouldn't want us to draw a conclusion over possibly baseless assumptions.

  14. mcollina commented on Oct 24, 2022

    @mcollina
    SponsorMember

    Absolutely! I'm concerned about the addition to our startup memory footprint, as this matters for some of our usecases.

    I'm flagging that this might be problematic and I was surprised because it was not mentioned in the main text of the issue.

    A few more question:

    1. if a new Worker thread is spawned in the lifetime of the application, will this create another thread to load ESM?
    2. what about dynamic import? Will it need re-spawning the thread?
  15. JakobJingleheimer commented on Oct 24, 2022

    @JakobJingleheimer
    MemberAuthor

    A few more question:

    1. if a new Worker thread is spawned in the lifetime of the application, will this create another thread to load ESM?
    2. what about dynamic import? Will it need re-spawning the thread?

    In both cases, (in the current design/implementation) only if the "loaders" worker is not around (otherwise it will be re-used).

  16. mcollina commented on Oct 24, 2022

    @mcollina
    SponsorMember

    In both cases, (in the current design/implementation) only if the "loaders" worker is not around (otherwise it will be re-used).

    So there is only one loaders worker for all worker threads created by Node.js?

  17. targos commented on Oct 24, 2022

    @targos
    Member

    No, there's a separate loaders worker for each worker thread.

  18. Flarna commented on Oct 24, 2022

    @Flarna
    Member

    I assume it should be possible to configure loader hooks per worker thread therefore this may complicate this thread.

    I'm also a bit skeptical to have a single loader thread for all workers as this seems to allow "leaking" data between workers which should be isolated. Also this single loader worker would be parallelism blocker.

  19. removed
    tsc-agendaIssues and PRs to discuss during Technical Steering Committee meetings.
    on Nov 1, 2022
  20. mhdawson commented on Nov 1, 2022

    @mhdawson
    Member

    The comment from @targos and @JakobJingleheimer seem contradictory?

  21. cspotcode commented on Nov 1, 2022

    @cspotcode

    There are 3 different threading models being considered, that I'm aware of.

  22. JakobJingleheimer commented on Nov 1, 2022

    @JakobJingleheimer
    MemberAuthor

    Sorry, I think #43658 (comment) is the intended behaviour (the current PR may not achieve that yet). The rationale being that workers are intended to be isolated, so their loaders' state should also be isolated/fresh.

  23. JakobJingleheimer commented on Nov 13, 2022

    @JakobJingleheimer
    MemberAuthor

    Quick update from our recent team meeting: We invited Gil Tayar (author/maintainer of several pertinent libraries) to discuss spawning a dedicated loaders thread per user-land thread, and he noted that will add enormous complexity to library authors (on top of the extra complexity on node's side). We decided for an initial implementation, it would be better to use a single loaders thread shared by all user-land threads and add caveats to the relevant sections of the docs. If there is sufficient appetite, we can subsequently add a configuration option (perhaps to the Worker constructor) to spawn dedicated loaders threads.

  24. mcollina commented on Nov 14, 2022

    @mcollina
    SponsorMember

    Was there any progress on not spawning any thread if no custom loaders are defined?

  25. JakobJingleheimer commented on Nov 15, 2022

    @JakobJingleheimer
    MemberAuthor

    Yep! nodejs/loaders#118 (comment) and I believe this should be logistically/technically possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loaders.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions