Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use specific allocator on different platform #912

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading