Skip to content

Commit b93461e

Browse files
committed
perf(js): Use mimalloc on some platforms
1 parent e944a5b commit b93461e

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

bindings/javascript/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ crate-type = ["cdylib"]
1919
napi = { version = "2.14.1", default-features = false, features = ["napi4"] }
2020
napi-derive = "2.14.4"
2121

22+
[target.'cfg(all(not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")), not(all(target_os = "windows", target_arch = "aarch64")), not(target_arch = "wasm32")))'.dependencies]
23+
mimalloc-rust = { version = "0.2" }
24+
2225
[target.'cfg(target_arch = "wasm32")'.dependencies]
2326
attohttpc = { version = "0.24", default-features = false }
2427
wasm-bindgen = "0.2.87"

bindings/javascript/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ Here is the performance comparison:
141141

142142
| | Size | `css-inline 0.11.2` | `css-inline-wasm 0.11.2` | `juice 10.0.0` | `inline-css 4.0.2` |
143143
|-------------|---------|---------------------|--------------------------|-----------------------|------------------------|
144-
| Basic | 230 B | 15.19 µs | 29.33 µs (**1.93x**) | 142.53 µs (**9.38x**) | 163.77 µs (**10.78x**) |
145-
| Realistic-1 | 8.58 KB | 336.81 µs | 638.97 µs (**1.90x**) | 1.28 ms (**3.80x**) | 1.87 ms (**5.57x**) |
146-
| Realistic-2 | 4.3 KB | 210.52 µs | 385.20 µs (**1.82x**) | 1.72 ms (**8.18x**) | 1.56 ms (**7.44x**) |
144+
| Basic | 230 B | 15.06 µs | 29.33 µs (**1.94x**) | 142.53 µs (**9.46x**) | 163.77 µs (**10.87x**) |
145+
| Realistic-1 | 8.58 KB | 320.71 µs | 638.97 µs (**1.99x**) | 1.28 ms (**4.01x**) | 1.87 ms (**5.85x**) |
146+
| Realistic-2 | 4.3 KB | 205.21 µs | 385.20 µs (**1.87x**) | 1.72 ms (**8.42x**) | 1.56 ms (**7.63x**) |
147147

148148
The "Basic" case was obtained from benchmarking the example from the Usage section.
149149

bindings/javascript/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ mod errors;
77
mod options;
88
use options::Options;
99

10+
#[cfg(all(
11+
not(target_arch = "wasm32"),
12+
not(debug_assertions),
13+
not(all(target_os = "windows", target_arch = "aarch64")),
14+
not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")),
15+
))]
16+
#[global_allocator]
17+
static ALLOC: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;
18+
1019
#[cfg(not(target_arch = "wasm32"))]
1120
#[napi]
1221
/// Inline CSS styles from <style> tags to matching elements in the HTML tree and return a string.

0 commit comments

Comments
 (0)