Skip to content

feat(wasm): add a dedicated zstd entry point - #252

Open
BridgeAR wants to merge 5 commits into
mainfrom
BridgeAR/2026-09-03-wasm-zstd-split
Open

BridgeAR wants to merge 5 commits into
mainfrom
BridgeAR/2026-09-03-wasm-zstd-split

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Sep 3, 2026

Copy link
Copy Markdown
Member

Builds Zstandard compression as a separate WASM crate and exposes typed CJS and ESM subpaths. The root API remains compatible through a lazy wrapper.

The direct entry point is 29,989 JavaScript bytes instead of 227,604, reducing loaded code by 86.8%. The published package grows by about 28 KiB.

Tested with the complete 49-test package and type suite, dependency validation, Clippy, and ESLint.

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Overall package size

Self size: 36.44 MB
Deduped: 36.44 MB
No deduping: 36.44 MB

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

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

@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-03-wasm-zstd-split branch from 055b23c to d0ae57d Compare September 3, 2026 20:53
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-03-wasm-zstd-split branch from d0ae57d to b779b13 Compare September 22, 2026 11:56
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

WASM size comparison

Compared e214315 (base) with 651f2df (PR merge).

Artifact Before After Change
libdatadog 244,451 (238.7 KiB) 242,332 (236.7 KiB) -2,119 (-0.87%)
remote config 336,768 (328.9 KiB) 336,768 (328.9 KiB) 0 (0.00%)

Negative changes reduce size.
Crate sizes come from symbol-preserving builds with debug names excluded and generic functions assigned to their symbol owner.

libdatadog: 21 changed, 25 unchanged

Inline artifact layers

Inline artifact layer Before After Change
Raw WASM (before Brotli) 492,791 (481.2 KiB) 488,825 (477.4 KiB) -3,966 (-0.80%)
Brotli-compressed WASM 167,943 (164.0 KiB) 166,525 (162.6 KiB) -1,418 (-0.84%)
Base64 encoding overhead 55,981 (54.7 KiB) 55,511 (54.2 KiB) -470 (-0.84%)
JavaScript glue/loader 20,527 (20.0 KiB) 20,296 (19.8 KiB) -231 (-1.13%)
Final inlined JavaScript 244,451 (238.7 KiB) 242,332 (236.7 KiB) -2,119 (-0.87%)

Raw WebAssembly sections

Section Before After Change
type 616 (0.6 KiB) 604 (0.6 KiB) -12 (-1.95%)
function 1,079 (1.1 KiB) 1,063 (1.0 KiB) -16 (-1.48%)
export 1,167 (1.1 KiB) 1,150 (1.1 KiB) -17 (-1.46%)
element 660 (0.6 KiB) 650 (0.6 KiB) -10 (-1.52%)
code 444,191 (433.8 KiB) 440,460 (430.1 KiB) -3,731 (-0.84%)
data 41,470 (40.5 KiB) 41,290 (40.3 KiB) -180 (-0.43%)
header 8 (0.0 KiB) 8 (0.0 KiB) 0 (0.00%)
import 3,257 (3.2 KiB) 3,257 (3.2 KiB) 0 (0.00%)
table 13 (0.0 KiB) 13 (0.0 KiB) 0 (0.00%)
memory 5 (0.0 KiB) 5 (0.0 KiB) 0 (0.00%)
global 27 (0.0 KiB) 27 (0.0 KiB) 0 (0.00%)
data count 3 (0.0 KiB) 3 (0.0 KiB) 0 (0.00%)
custom 295 (0.3 KiB) 295 (0.3 KiB) 0 (0.00%)

Code by Rust crate

Crate/function owner Before After Change
Rust standard library 65,470 (63.9 KiB) 65,379 (63.8 KiB) -91 (-0.14%)
zrip-encode 41,358 (40.4 KiB) 41,245 (40.3 KiB) -113 (-0.27%)
regex-lite 28,248 (27.6 KiB) 28,246 (27.6 KiB) -2 (-0.01%)
libdd-trace-utils 24,499 (23.9 KiB) 24,433 (23.9 KiB) -66 (-0.27%)
bindings / unattributed 22,847 (22.3 KiB) 21,226 (20.7 KiB) -1,621 (-7.10%)
serde-json 12,421 (12.1 KiB) 12,419 (12.1 KiB) -2 (-0.02%)
serde-transcode 10,093 (9.9 KiB) 10,091 (9.9 KiB) -2 (-0.02%)
zrip-core 3,631 (3.5 KiB) 1,909 (1.9 KiB) -1,722 (-47.42%)
fluent-uri 3,463 (3.4 KiB) 3,461 (3.4 KiB) -2 (-0.06%)
js-sys 2,390 (2.3 KiB) 2,272 (2.2 KiB) -118 (-4.94%)
libdatadog-wasm 58,088 (56.7 KiB) 58,088 (56.7 KiB) 0 (0.00%)
libdd-trace-obfuscation 42,144 (41.2 KiB) 42,144 (41.2 KiB) 0 (0.00%)
http 22,303 (21.8 KiB) 22,303 (21.8 KiB) 0 (0.00%)
rustc-demangle 16,094 (15.7 KiB) 16,094 (15.7 KiB) 0 (0.00%)
hashbrown 11,516 (11.2 KiB) 11,516 (11.2 KiB) 0 (0.00%)
libdd-trace-stats 11,441 (11.2 KiB) 11,441 (11.2 KiB) 0 (0.00%)
rmp 11,039 (10.8 KiB) 11,039 (10.8 KiB) 0 (0.00%)
rmp-serde 9,266 (9.0 KiB) 9,266 (9.0 KiB) 0 (0.00%)
anyhow 9,080 (8.9 KiB) 9,080 (8.9 KiB) 0 (0.00%)
dlmalloc 5,071 (5.0 KiB) 5,071 (5.0 KiB) 0 (0.00%)
crossbeam-channel 4,269 (4.2 KiB) 4,269 (4.2 KiB) 0 (0.00%)
rand-chacha 4,267 (4.2 KiB) 4,267 (4.2 KiB) 0 (0.00%)
libdd-trace-protobuf 4,176 (4.1 KiB) 4,176 (4.1 KiB) 0 (0.00%)
bytes 3,875 (3.8 KiB) 3,875 (3.8 KiB) 0 (0.00%)
libdd-common 2,806 (2.7 KiB) 2,806 (2.7 KiB) 0 (0.00%)
libdd-ddsketch 2,403 (2.3 KiB) 2,403 (2.3 KiB) 0 (0.00%)
zmij 2,243 (2.2 KiB) 2,243 (2.2 KiB) 0 (0.00%)
other crates (<2 KiB in both builds) 9,670 (9.4 KiB) 9,670 (9.4 KiB) 0 (0.00%)
remote config: 0 changed, 43 unchanged

Inline artifact layers

Inline artifact layer Before After Change
Raw WASM (before Brotli) 720,147 (703.3 KiB) 720,147 (703.3 KiB) 0 (0.00%)
Brotli-compressed WASM 230,616 (225.2 KiB) 230,616 (225.2 KiB) 0 (0.00%)
Base64 encoding overhead 76,872 (75.1 KiB) 76,872 (75.1 KiB) 0 (0.00%)
JavaScript glue/loader 29,280 (28.6 KiB) 29,280 (28.6 KiB) 0 (0.00%)
Final inlined JavaScript 336,768 (328.9 KiB) 336,768 (328.9 KiB) 0 (0.00%)

Raw WebAssembly sections

Section Before After Change
header 8 (0.0 KiB) 8 (0.0 KiB) 0 (0.00%)
type 574 (0.6 KiB) 574 (0.6 KiB) 0 (0.00%)
import 4,790 (4.7 KiB) 4,790 (4.7 KiB) 0 (0.00%)
function 2,193 (2.1 KiB) 2,193 (2.1 KiB) 0 (0.00%)
table 13 (0.0 KiB) 13 (0.0 KiB) 0 (0.00%)
memory 5 (0.0 KiB) 5 (0.0 KiB) 0 (0.00%)
global 33 (0.0 KiB) 33 (0.0 KiB) 0 (0.00%)
export 1,139 (1.1 KiB) 1,139 (1.1 KiB) 0 (0.00%)
element 1,550 (1.5 KiB) 1,550 (1.5 KiB) 0 (0.00%)
data count 4 (0.0 KiB) 4 (0.0 KiB) 0 (0.00%)
code 629,686 (614.9 KiB) 629,686 (614.9 KiB) 0 (0.00%)
data 79,830 (78.0 KiB) 79,830 (78.0 KiB) 0 (0.00%)
custom 322 (0.3 KiB) 322 (0.3 KiB) 0 (0.00%)

Code by Rust crate

Crate/function owner Before After Change
serde-json 96,377 (94.1 KiB) 96,377 (94.1 KiB) 0 (0.00%)
tuf 96,309 (94.1 KiB) 96,309 (94.1 KiB) 0 (0.00%)
Rust standard library 93,533 (91.3 KiB) 93,533 (91.3 KiB) 0 (0.00%)
libdd-remote-config 79,352 (77.5 KiB) 79,352 (77.5 KiB) 0 (0.00%)
data-encoding 40,626 (39.7 KiB) 40,626 (39.7 KiB) 0 (0.00%)
bindings / unattributed 36,298 (35.4 KiB) 36,298 (35.4 KiB) 0 (0.00%)
http 27,758 (27.1 KiB) 27,758 (27.1 KiB) 0 (0.00%)
hashbrown 25,059 (24.5 KiB) 25,059 (24.5 KiB) 0 (0.00%)
ring 17,349 (16.9 KiB) 17,349 (16.9 KiB) 0 (0.00%)
js-sys 15,849 (15.5 KiB) 15,849 (15.5 KiB) 0 (0.00%)
rustc-demangle 13,732 (13.4 KiB) 13,732 (13.4 KiB) 0 (0.00%)
anyhow 13,201 (12.9 KiB) 13,201 (12.9 KiB) 0 (0.00%)
sha2 10,885 (10.6 KiB) 10,885 (10.6 KiB) 0 (0.00%)
rand-chacha 6,242 (6.1 KiB) 6,242 (6.1 KiB) 0 (0.00%)
serde-wasm-bindgen 5,654 (5.5 KiB) 5,654 (5.5 KiB) 0 (0.00%)
prost 4,955 (4.8 KiB) 4,955 (4.8 KiB) 0 (0.00%)
dlmalloc 4,686 (4.6 KiB) 4,686 (4.6 KiB) 0 (0.00%)
serde 4,254 (4.2 KiB) 4,254 (4.2 KiB) 0 (0.00%)
base64 3,475 (3.4 KiB) 3,475 (3.4 KiB) 0 (0.00%)
libdd-common 3,220 (3.1 KiB) 3,220 (3.1 KiB) 0 (0.00%)
libdd-trace-protobuf 3,126 (3.1 KiB) 3,126 (3.1 KiB) 0 (0.00%)
bytes 2,706 (2.6 KiB) 2,706 (2.6 KiB) 0 (0.00%)
compiler-builtins 2,419 (2.4 KiB) 2,419 (2.4 KiB) 0 (0.00%)
zmij 2,296 (2.2 KiB) 2,296 (2.2 KiB) 0 (0.00%)
other crates (<2 KiB in both builds) 20,319 (19.8 KiB) 20,319 (19.8 KiB) 0 (0.00%)

@BridgeAR
BridgeAR marked this pull request as ready for review September 22, 2026 12:44
@BridgeAR
BridgeAR requested review from a team as code owners September 22, 2026 12:44

@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: b779b13613

ℹ️ 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 crates/libdatadog-wasm-zstd/Cargo.toml
Comment thread packages/libdatadog/package.json Outdated
"scripts": {
"benchmark:agentless": "npm run build:wasm:binary && npm run inline:wasm && node benchmark/agentless-pipeline.js",
"build:wasm": "npm run build:wasm:binary && npm run build:remote-config:binary && npm run inline:wasm && npm run inline:remote-config",
"build:wasm": "npm run build:wasm:binary && npm run build:zstd:binary && npm run build:remote-config:binary && npm run inline:wasm && npm run inline:zstd && npm run inline:remote-config",

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.

Nit: could we simplify all those long scripts to small ones?

Consumers that only need Zstandard compression currently load the exporter, DDSketch, and their transitive Rust code. Build compression as a separate WASM crate and expose it through a typed subpath while keeping the root API as a lazy compatibility wrapper.

The direct entry point is 29,989 JavaScript bytes instead of 227,604 (86.8% less loaded code). The package grows by about 28 KiB so existing consumers remain compatible.
The root zstd_compress wrapper now loads the dedicated artifact, but the optimization flags and Binaryen profile were scoped to the original WASM crate. Apply them to both compression crates so the compatibility path retains the measured Zstandard optimization.
The split Zstandard profile omitted the Binaryen --disable-gc guard, so Node.js 18 could reject the generated module. Restore the guard used by the existing WASM profile.

The package command serialized each artifact build and inline step. Run the artifact pipelines concurrently while preserving each build-before-inline dependency.
The compatibility wrapper resolved the split Zstandard binding on every compression call. Cache it after the first use while preserving lazy loading for consumers that do not use Zstandard.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-03-wasm-zstd-split branch from b779b13 to 01d5d56 Compare September 22, 2026 13:28

This branch has not been deployed

No deployments
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.

2 participants