Skip to content

Commit

Permalink
perf: use specific allocator on different platform (#912)
Browse files Browse the repository at this point in the history
* perf: use specific allocator on different platform

* fix: move allocation declare to lib entry
  • Loading branch information
xusd320 authored Feb 19, 2024
1 parent 544c3b7 commit d81af88
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 5 deletions.
50 changes: 50 additions & 0 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ resolver = "2"
members = ["crates/*"]

[workspace.dependencies]
serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.100"
cached = "0.46.1"
swc_core = { version = "=0.83.19", default-features = false }
mimalloc-rust = { version = "=0.2.1" }
serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.100"
cached = "0.46.1"
swc_core = { version = "=0.83.19", default-features = false }
tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] }
6 changes: 6 additions & 0 deletions crates/mako/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ swc_core = { workspace = true, features = ["swc_ecma_quote_macros"] }
miette = { version = "5.10.0", features = ["fancy"] }
glob-match = "0.2.1"

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

[target.'cfg(all(target_os = "linux", target_env = "gnu", any(target_arch = "x86_64", target_arch = "aarch64")))'.dependencies]
tikv-jemallocator = { workspace = true }

[dev-dependencies]
insta = { version = "1.30.0", features = ["yaml"] }
maplit = "1.0.2"
Expand Down
12 changes: 12 additions & 0 deletions crates/mako/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ mod update;
mod util;
mod watch;

#[cfg(not(target_os = "linux"))]
#[global_allocator]
static GLOBAL: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;

#[cfg(all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[tokio::main]
async fn main() -> Result<()> {
// logger
Expand Down
6 changes: 6 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ mako_core = { path = "../core" }
serde_json = { workspace = true }
cached = { workspace = true }

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

[target.'cfg(all(target_os = "linux", target_env = "gnu", any(target_arch = "x86_64", target_arch = "aarch64")))'.dependencies]
tikv-jemallocator = { workspace = true }

[build-dependencies]
napi-build = "2.0.1"

Expand Down
3 changes: 2 additions & 1 deletion crates/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"@okamjs/okam-darwin-arm64": "0.4.3",
"@okamjs/okam-darwin-x64": "0.4.3",
"@okamjs/okam-linux-x64-gnu": "0.4.3"
}
},
"repository": "[email protected]:umijs/mako.git"
}
12 changes: 12 additions & 0 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ mod tsfn;

pub(crate) mod threadsafe_function;

#[cfg(not(target_os = "linux"))]
#[global_allocator]
static GLOBAL: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;

#[cfg(all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

static LOG_INIT: Once = Once::new();

#[napi(object)]
Expand Down

0 comments on commit d81af88

Please sign in to comment.