From 798c1ad0f1de80ff0e7196b6140a3f74e31fe111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 3 May 2023 00:36:33 +0200 Subject: perf: use jemalloc as global allocator (#18957) Follow up to https://github.com/denoland/deno/pull/18875 that enables `jemalloc` as a global allocator for the Deno CLI. --- cli/Cargo.toml | 3 +++ cli/main.rs | 7 +++++++ cli/napi/async.rs | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 319c8cb56..63842a6a3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -120,6 +120,9 @@ winapi = { workspace = true, features = ["knownfolders", "mswsock", "objbase", " [target.'cfg(unix)'.dependencies] nix.workspace = true +[target.'cfg(not(target_env = "msvc"))'.dependencies] +tikv-jemallocator.workspace = true + [dev-dependencies] deno_bench_util.workspace = true dotenv = "=0.15.0" diff --git a/cli/main.rs b/cli/main.rs index 85942cbd8..c3421b0cd 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -26,6 +26,13 @@ mod version; mod watcher; mod worker; +#[cfg(not(target_env = "msvc"))] +use tikv_jemallocator::Jemalloc; + +#[cfg(not(target_env = "msvc"))] +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + use crate::args::flags_from_vec; use crate::args::DenoSubcommand; use crate::args::Flags; diff --git a/cli/napi/async.rs b/cli/napi/async.rs index 8cbdb2220..e6695551a 100644 --- a/cli/napi/async.rs +++ b/cli/napi/async.rs @@ -24,7 +24,8 @@ fn napi_create_async_work( execute, complete, }; - *result = transmute::, _>(Box::new(work)); + let work_box = Box::new(work); + *result = transmute::<*mut AsyncWork, _>(Box::into_raw(work_box)); Ok(()) } -- cgit v1.2.3