Skip to content

Commit

Permalink
perf: use mimalloc for bindings_napi (#5201)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Oct 15, 2023
1 parent cb144b2 commit f3eaa28
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions rust/bindings_napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ napi-derive = "2.13.0"
parse_ast = { path = "../parse_ast" }
xxhash = { path = "../xxhash" }

[target.'cfg(not(target_os = "linux"))'.dependencies]
mimalloc-rust = { version = "0.2" }

[target.'cfg(all(target_os = "linux", not(all(target_env = "musl", target_arch = "aarch64"))))'.dependencies]
mimalloc-rust = { version = "0.2", features = ["local-dynamic-tls"] }

[build-dependencies]
napi-build = "2.0.1"
7 changes: 7 additions & 0 deletions rust/bindings_napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ use napi::bindgen_prelude::*;
use napi_derive::napi;
use parse_ast::parse_ast;

#[cfg(all(
not(all(target_os = "linux", target_env = "musl", target_arch = "aarch64")),
not(debug_assertions)
))]
#[global_allocator]
static ALLOC: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;

#[napi]
pub fn parse(code: String, allow_return_outside_function: bool) -> Buffer {
parse_ast(code, allow_return_outside_function).into()
Expand Down

0 comments on commit f3eaa28

Please sign in to comment.