From c0f2808d42fcd73d804243fbd06195288c5bc5dc Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 31 Jul 2026 16:29:38 -0400 Subject: [PATCH] perf(pipeline): use regex-lite in the wasm build libdd-common declares regex as a non-optional dependency, resolved with every unicode feature enabled, so the pipeline wasm carried ~394 KB of unicode range tables and a full regex engine for code that never evaluates a regex. Enabling libdd-common's regex-lite feature leaves the full regex crate unreferenced, and LTO drops it. With wasm-opt -O, matching what CI publishes, pipeline_bg.wasm goes from 1,507,189 to 754,457 bytes raw (-49.9%) and 564,771 to 304,880 bytes gzipped (-46.0%). The code section shrinks 39.8% and the data section 72.6%. This is safe because the call sites that compile user-supplied patterns are not reachable here: obfuscation in libdd-data-pipeline sits behind its stats-obfuscation feature, which this crate does not enable, and nothing in crates/pipeline or crates/capabilities builds a Regex or calls trace_filter. require-regex-full, which would override regex-lite, is only enabled by datadog-ffe, which is not in this dependency graph. test/pipeline.js passes 51/51 and test/http_transport.js 18/18 against the rebuilt module. --- Cargo.lock | 7 +++++++ crates/pipeline/Cargo.toml | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 22d82132..90259f14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1008,6 +1008,7 @@ dependencies = [ "nix 0.29.0", "pin-project", "regex", + "regex-lite", "serde", "static_assertions", "thiserror", @@ -1989,6 +1990,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-lite" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" + [[package]] name = "regex-syntax" version = "0.8.10" diff --git a/crates/pipeline/Cargo.toml b/crates/pipeline/Cargo.toml index f8e318a3..a923ff5f 100644 --- a/crates/pipeline/Cargo.toml +++ b/crates/pipeline/Cargo.toml @@ -17,7 +17,13 @@ libdatadog-nodejs-capabilities = { path = "../capabilities" } # TODO: Replace these temporary libdatadog PR revs with the official release/tag # that contains DataDog/libdatadog#2235, then regenerate Cargo.lock. libdd-capabilities = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af" } -libdd-common = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af", default-features = false } +# `regex-lite` swaps libdd-common's regex engine for the `regex-lite` crate, +# dropping the Unicode range tables that dominate this wasm module. Nothing in +# the wasm build evaluates user-supplied regexes: libdd-trace-obfuscation and +# libdd-trace-utils::trace_filter both go through `libdd_common::regex_engine`, +# and `require-regex-full` (which would override this) is only enabled by +# datadog-ffe, which is not in this dependency graph. +libdd-common = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af", default-features = false, features = ["regex-lite"] } libdd-data-pipeline = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af", default-features = false } libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af", default-features = false, features = ["change-buffer"] } libdd-trace-stats = { git = "https://github.com/DataDog/libdatadog.git", rev = "8cd68ab922fb7aade0f089ccfc91291d874673af", default-features = false }