Skip to content

Conversation

tniessen
Copy link
Member

Now that we have fetch(), we may as well also have WebAssembly.compileStreaming() and WebAssembly.instantiateStreaming().

Unfortunately, our fetch() implementation cannot be interacted with easily from C++, which is why part of this implementation ended up in JavaScript. The C++ glue code allows controlling the v8::WasmStreaming instance from JavaScript.

This attempts to be a spec-compliant implementation with no node-specific extensions.

Refs: #41749
Fixes: #21130

@tniessen tniessen added notable-change PRs with changes that should be highlighted in changelogs. wasm Issues and PRs related to WebAssembly. fetch Issues and PRs related to the Fetch API labels Apr 12, 2022
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 12, 2022
new WasmStreamingObject(env, args.This());
}

void WasmStreamingObject::Push(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless i am mistaken, these methods do not allocate. would you be up for adding fast call wrappers? if not i can maybe add them in a followup pr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try that tomorrow. So far, every time I tried using fast calls, I can into some V8 limitation, but Push might be a good candidate for once.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, given how web streams are performing so far and how slow everything is, that seems like premature optimization. I might create a follow-up PR to add that or I might push that as a separate commit later, but I'd like to get this landed rather sooner than later and not make it more complicated to review.

@targos targos added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 12, 2022
@tniessen tniessen force-pushed the wasm-web-api branch 4 times, most recently from f76bda6 to 8689723 Compare April 13, 2022 00:58
@tniessen tniessen added the review wanted PRs that need reviews. label Apr 17, 2022
@tniessen tniessen added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 17, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 17, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add WTP tests? Maybe https://github.com/web-platform-tests/wpt/tree/HEAD/wasm/webapi or a subset of it?

@tniessen
Copy link
Member Author

Should we add WTP tests?

That's a good idea. It's not straightforward because many WPT tests for this API rely on fetch and we currently mock fetch in WPT.

Of the ones I can run easily, wasm/webapi/empty-body.any.js is failing, presumably due to nodejs/undici#1345.

@aduh95
Copy link
Contributor

aduh95 commented Apr 18, 2022

Should we add WTP tests?

That's a good idea. It's not straightforward because many WPT tests for this API rely on fetch and we currently mock fetch in WPT.

Of the ones I can run easily, wasm/webapi/empty-body.any.js is failing, presumably due to nodejs/undici#1345.

I think you can create a status file that lists all the failing tests, and that can be used as a TODO list for contributors who want to improve Node.js API compliance. But maybe that's a lot of work (I've never done that myself so not sure), and it probably should not block this from landing.

@juanarbol
Copy link
Member

I think it's fine to land it on v16.x, because it's behind the --experimental-fetch flag.

Yeap, it does, It lands fine; except for the bootstrap, tried to fix this by adding the binding wasm_web_api to lib/internal/bootstrap/loaders.js with no sucess, I will label this to request backport:

make[1]: Leaving directory '/home/juanarbol/GitHub/node/test/node-api/test_worker_terminate_finalization/build'                                     [487/5756]
/usr/bin/python3.10 tools/test.py  --mode=release \                                                                                                           
         \                                                                                                                                                    
        --skip-tests= \                                                                                                                                       
        default \                                                                                                                                             
        addons js-native-api node-api                                                                                                                         
=== release test-bootstrap-modules ===                                                                                                                        
Path: parallel/test-bootstrap-modules                                                                                                                         
node:assert:123                                                                                                                                               
  throw new AssertionError(obj);                                                                                                                              
  ^                                                                                                                                                           
                                                                                                                                                              
AssertionError [ERR_ASSERTION]: These modules were not loaded:                                                                                                
  Internal Binding wasm_web_api                                                                                                                               
                                                                                                                                                              
    at Object.<anonymous> (/home/juanarbol/GitHub/node/test/parallel/test-bootstrap-modules.js:216:8)                                                         
    at Module._compile (node:internal/modules/cjs/loader:1105:14)                                                                                             
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)                                                                               
    at Module.load (node:internal/modules/cjs/loader:981:32)                                                                                                  
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)                                                                                        
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)                                                                     
    at node:internal/main/run_main_module:17:47 {

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. experimental Issues and PRs related to experimental features. fetch Issues and PRs related to the Fetch API lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version. wasm Issues and PRs related to WebAssembly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support WebAssembly.instantiateStreaming
8 participants