Skip to content

Commit f3eaa28

Browse files
authored
perf: use mimalloc for bindings_napi (#5201)
1 parent cb144b2 commit f3eaa28

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎rust/Cargo.lock‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/bindings_napi/Cargo.toml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ napi-derive = "2.13.0"
1515
parse_ast = { path = "../parse_ast" }
1616
xxhash = { path = "../xxhash" }
1717

18+
[target.'cfg(not(target_os = "linux"))'.dependencies]
19+
mimalloc-rust = { version = "0.2" }
20+
21+
[target.'cfg(all(target_os = "linux", not(all(target_env = "musl", target_arch = "aarch64"))))'.dependencies]
22+
mimalloc-rust = { version = "0.2", features = ["local-dynamic-tls"] }
23+
1824
[build-dependencies]
1925
napi-build = "2.0.1"

‎rust/bindings_napi/src/lib.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ use napi::bindgen_prelude::*;
22
use napi_derive::napi;
33
use parse_ast::parse_ast;
44

5+
#[cfg(all(
6+
not(all(target_os = "linux", target_env = "musl", target_arch = "aarch64")),
7+
not(debug_assertions)
8+
))]
9+
#[global_allocator]
10+
static ALLOC: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;
11+
512
#[napi]
613
pub fn parse(code: String, allow_return_outside_function: bool) -> Buffer {
714
parse_ast(code, allow_return_outside_function).into()

0 commit comments

Comments
 (0)