Git Product home page Git Product logo

Comments (9)

littledan avatar littledan commented on June 10, 2024 1

OK, if we do want to keep them well-ordered, then the actual requirement is a little more subtle: We should start instantiation as soon as the dependencies (which might export types) are available, and then execute the start function exactly in order, based on the same sibling ordering that JS modules have. This means we need a sort of synchronization barrier in the middle of the WebAssembly instantiation algorithm.

from esm-integration.

littledan avatar littledan commented on June 10, 2024 1

Sounds like we are on the same page. In particular, the compilation work can be done ahead of time even in platforms that do that compilation as part of their instantiation API.

I think we all agree that startup should be fast, and just have different theories about how long this pause would be. What should be our next steps to getting data on this question?

from esm-integration.

xtuc avatar xtuc commented on June 10, 2024

Wasm compilation will be done in parallel and the instantiation on the main thread (actually blocking it).

We need to make sure that the ordering is respected, given that compilation times are variables it will require a bit of bookeping, but the module graph will indicate the order.

Note that wasm modules with no dependencies can be instantiated (including the start func evaluation) in any order (we do this already in Webpack).

from esm-integration.

littledan avatar littledan commented on June 10, 2024

Note that wasm modules with no dependencies can be instantiated (including the start func evaluation) in any order (we do this already in Webpack).

This is a design question: Do we want to allow implementations to execute the start function in any order, or should this be deterministic based on the ordering of the imports that led to its use? ESM+HTML makes this deterministic for JS, I believe.

from esm-integration.

xtuc avatar xtuc commented on June 10, 2024

They SHOULD be deterministic and ordered, because they can cause side-effects. You can run any JS function during the start.

from esm-integration.

sokra avatar sokra commented on June 10, 2024

We should start instantiation as soon as the dependencies (which might export types) are available

As the order of the dependencies is also defined the same way, this leads to no optimization:

- a.js
  - x.wasm
    - b.js
    - c.js
  - y.wasm
    - d.js
    - e.js

The execution order is:

b, c, x, d, e, y, a

The dependencies are exactly at the time available when execution should happen. You can't start instantiation earlier. You can't order the dependencies of wasm modules because they could have side-effects and their execution order is well defined.

There actually is an edgecase where you could start instantiation earlier, but that is very rare: All dependencies of the wasm module are referenced by some modules earlier in the graph, like this:

- a.js
  - d.js
  - e.js
  - x.wasm
    - b.js
    - c.js
  - y.wasm
    - d.js
    - e.js

d, e, (y instantiation), b, c, x, y start function, a

But this is too rare to make any difference.

=> When running instantiation while evaluation phase it will cause sequential instantiation of wasm modules. => Bad for performance

from esm-integration.

littledan avatar littledan commented on June 10, 2024

@sokra If we schedule the heavy parts of instantiation (chiefly, compilation) ahead of time, are you still worried about the startup time impact? Can you think of any benchmarks/simulations we could do to assess the impact now while we are in the design phase?

from esm-integration.

xtuc avatar xtuc commented on June 10, 2024

Downloading and compiling can be done at any time in any order because that isn't causing any side-effects.

Instantiation must respect the order, as said before.

from esm-integration.

littledan avatar littledan commented on June 10, 2024

The current specification is in terms of the top-level await proposal, so this issue can be closed.

from esm-integration.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.