diff --git a/Cargo.lock b/Cargo.lock index fe9d07c33..31d6748e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,10 +153,12 @@ dependencies = [ "cached", "mako", "mako_core", + "mimalloc-rust", "napi", "napi-build", "napi-derive", "serde_json", + "tikv-jemallocator", ] [[package]] @@ -1148,6 +1150,12 @@ dependencies = [ "syn 2.0.32", ] +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + [[package]] name = "daachorse" version = "1.0.0" @@ -2539,11 +2547,13 @@ dependencies = [ "mako_core", "maplit", "miette 5.10.0", + "mimalloc-rust", "serde", "serde_json", "swc_core 0.83.19", "swc_ecma_transforms_testing", "testing 0.35.10", + "tikv-jemallocator", ] [[package]] @@ -2763,6 +2773,26 @@ dependencies = [ "syn 2.0.32", ] +[[package]] +name = "mimalloc-rust" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb726c8298efb4010b2c46d8050e4be36cf807b9d9e98cb112f830914fc9bbe" +dependencies = [ + "cty", + "mimalloc-rust-sys", +] + +[[package]] +name = "mimalloc-rust-sys" +version = "1.7.9-source" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6413e13241a9809f291568133eca6694572cf528c1a6175502d090adce5dd5db" +dependencies = [ + "cc", + "cty", +] + [[package]] name = "mime" version = "0.3.17" @@ -6232,6 +6262,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.5.4+5.3.0-patched" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9402443cb8fd499b6f327e40565234ff34dbda27460c5b47db0db77443dd85d1" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965fe0c26be5c56c94e38ba547249074803efd52adfb66de62107d95aab3eaca" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.22" diff --git a/Cargo.toml b/Cargo.toml index f06a0165d..c937b7086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/crates/mako/Cargo.toml b/crates/mako/Cargo.toml index 83a63996a..7a3e4468f 100644 --- a/crates/mako/Cargo.toml +++ b/crates/mako/Cargo.toml @@ -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" diff --git a/crates/mako/src/main.rs b/crates/mako/src/main.rs index 65fec9798..184664980 100644 --- a/crates/mako/src/main.rs +++ b/crates/mako/src/main.rs @@ -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 diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 299734058..dc4f052b5 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -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" diff --git a/crates/node/package.json b/crates/node/package.json index 2c1932984..df3a3950f 100644 --- a/crates/node/package.json +++ b/crates/node/package.json @@ -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": "git@github.com:umijs/mako.git" } \ No newline at end of file diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index f74c96754..b34e77716 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -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)]