Skip to content

refactor(libdatadog): share napi bindings without wasi - #213

Closed
rochdev wants to merge 6 commits into
mainfrom
rochdev/napi-rs-inline-wasm
Closed

rochdev wants to merge 6 commits into
mainfrom
rochdev/napi-rs-inline-wasm

Conversation

@rochdev

@rochdev rochdev commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Deduplicates the native N-API and WASM bindings by building both artifacts
from the shared libdatadog crate. The WASM fallback targets
wasm32-unknown-unknown, uses the napi-rs current-thread async runtime, and
does not require WASI or worker permissions.

Details

  • Removes the separate libdatadog-wasm Rust crate and its duplicated bindings.
  • Builds the shared binding crate for native N-API and
    wasm32-unknown-unknown.
  • Transforms the raw WASM with a pinned wasm-bindgen build helper while
    preserving napi-rs exports.
  • Instantiates the binding with emnapi and installs the official napi-rs
    current-thread task host for async exports.
  • Brotli-compresses and embeds the WASM and complete JavaScript runtime in one
    self-contained entry point with no separate runtime assets.
  • Preserves the native-first universal package with the self-contained WASM
    package as its fallback.
  • Verifies that the fallback loads under Node's permission model without
    --allow-wasi or --allow-worker.
  • Updates dependency validation, release CI, and size reporting for the new
    target.

Compared with the separate wasm-bindgen implementation on the base commit:

Size Before After Increase
Raw WASM 317,842 B 463,436 B 145,594 B
Final inlined JavaScript 153,310 B 249,024 B 95,714 B
Brotli-compressed final JavaScript 103,668 B 187,168 B 83,500 B
Published WASM package tarball 106,137 B 188,308 B 82,171 B

The published package contains no separate runtime or worker files.

Validation

  • 41 runtime, parity, exporter, transport, bundler, package, permission, and
    size-report tests on Node 24.
  • WASM, exporter, and bundler coverage on Node 18; the unsupported permission
    flag test is skipped there.
  • Strict TypeScript type checking.
  • ESLint.
  • cargo clippy --package libdatadog --target wasm32-unknown-unknown -- -D warnings.
  • Artifact dependency and forbidden-code validation.

This PR was generated by Codex.

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Overall package size

Self size: 53.9 MB
Deduped: 53.9 MB
No deduping: 53.9 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------|

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@rochdev
rochdev marked this pull request as ready for review August 27, 2026 19:58
@rochdev
rochdev requested review from a team as code owners August 27, 2026 19:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a1ce25dac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/libdatadog/scripts/inline-wasm.js Outdated
@rochdev rochdev changed the title refactor(libdatadog): share napi bindings with wasm refactor(libdatadog): share napi bindings without wasi Aug 27, 2026

@Aaalibaba42 Aaalibaba42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't really review the "js" side of the PR

Comment thread .cargo/config.toml
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]

[target.wasm32-wasip1-threads]
rustflags = ["--cfg", "tokio_unstable"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is, as per the name, unstable. The whole capability architecture was made so that we did not need to either compile to wasi nor have unstable/nightly features enabled. I'm not opposing this change of direction, but it has to be thought-out properly.

Node 24.20.0 / V8 13.6: option preparation drops from 469.11 to 4.23 ns/op when a runtime ID is present. When absent, it drops from 453.39 to 17.43 ns/op (1M iterations x 7 trials, drop best and worst).
@BridgeAR

Copy link
Copy Markdown
Member

Superseded, since napi is not being used

@BridgeAR BridgeAR closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants