diff --git a/Cargo.lock b/Cargo.lock index cb9d754e2ad..f3387e92a61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2176,6 +2176,26 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jemalloc-sys" +version = "0.5.4+5.3.0-patched" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac6c1946e1cea1788cbfde01c993b52a10e2da07f4bac608228d1bed20bfebf2" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "jemallocator" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0de374a9f8e63150e6f5e8a60cc14c668226d7a347d8aee1a45766e3c4dd3bc" +dependencies = [ + "jemalloc-sys", + "libc", +] + [[package]] name = "js-sys" version = "0.3.70" @@ -3800,6 +3820,7 @@ dependencies = [ "graphql-parser", "hyper", "indoc 2.0.3", + "jemallocator", "mongodb-query-connector", "prisma-metrics", "psl", @@ -3890,6 +3911,7 @@ dependencies = [ "connection-string", "driver-adapters", "futures", + "jemallocator", "napi", "napi-build", "napi-derive", diff --git a/Cargo.toml b/Cargo.toml index 53c478bb120..f06645292af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,6 +90,8 @@ url = { version = "2.5.0" } bson = { version = "2.11.0", features = ["chrono-0_4", "uuid-1"] } mongodb = { git = "https://github.com/prisma/mongo-rust-driver.git", branch = "RUST-1994/happy-eyeballs" } +jemallocator = "0.5.4" + [workspace.dependencies.quaint] path = "quaint" diff --git a/query-engine/query-engine-node-api/Cargo.toml b/query-engine/query-engine-node-api/Cargo.toml index a12e7a28675..457a1a1609f 100644 --- a/query-engine/query-engine-node-api/Cargo.toml +++ b/query-engine/query-engine-node-api/Cargo.toml @@ -53,6 +53,8 @@ tokio.workspace = true futures.workspace = true prisma-metrics.path = "../../libs/metrics" +jemallocator.workspace = true + [build-dependencies] napi-build = "1" build-utils.path = "../../libs/build-utils" diff --git a/query-engine/query-engine-node-api/src/lib.rs b/query-engine/query-engine-node-api/src/lib.rs index 3117dfd42d3..8964e2759f5 100644 --- a/query-engine/query-engine-node-api/src/lib.rs +++ b/query-engine/query-engine-node-api/src/lib.rs @@ -1,6 +1,11 @@ +use jemallocator::Jemalloc; + pub mod engine; pub mod error; pub mod functions; pub mod logger; pub(crate) type Result = std::result::Result; + +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; diff --git a/query-engine/query-engine/Cargo.toml b/query-engine/query-engine/Cargo.toml index 439a64f987c..e16c4bf7ce4 100644 --- a/query-engine/query-engine/Cargo.toml +++ b/query-engine/query-engine/Cargo.toml @@ -34,6 +34,8 @@ prisma-metrics.path = "../../libs/metrics" user-facing-errors = { path = "../../libs/user-facing-errors" } telemetry = { path = "../../libs/telemetry" } +jemallocator.workspace = true + [dev-dependencies] serial_test = "*" quaint.workspace = true diff --git a/query-engine/query-engine/src/main.rs b/query-engine/query-engine/src/main.rs index 17900c4ad74..0acddffdc67 100644 --- a/query-engine/query-engine/src/main.rs +++ b/query-engine/query-engine/src/main.rs @@ -1,5 +1,6 @@ #![allow(clippy::upper_case_acronyms)] +use jemallocator::Jemalloc; use query_engine::cli::CliCommand; use query_engine::context; use query_engine::error::PrismaError; @@ -9,6 +10,9 @@ use query_engine::LogFormat; use std::{error::Error, process}; use structopt::StructOpt; +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; + type AnyError = Box; #[tokio::main]