From 8e401a90c441b8b870c94113d25ae64b1f2cf53f Mon Sep 17 00:00:00 2001 From: Salvador Girones Gil Date: Tue, 5 Dec 2023 11:10:52 +0100 Subject: [PATCH] [mem] Use mimalloc instead of snmalloc (#3068) --- .github/workflows/nix.yml | 14 ++++++++++++ Cargo.lock | 48 ++++++++++++++++----------------------- Cargo.toml | 2 +- src/mem/mod.rs | 6 ++--- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index b40447ef..cfc513dc 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -13,6 +13,20 @@ defaults: shell: bash jobs: + build-static: + name: Build static Linux binary + if: ${{ github.ref == 'refs/heads/main' }} || ${{ github.event.label.name == 'nix' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v20 + - uses: cachix/cachix-action@v12 + with: + name: surrealdb + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + extraPullNames: nix-community + - run: nix build .#static-binary + - run: ./result/bin/surreal help build-docker: name: Build Docker image diff --git a/Cargo.lock b/Cargo.lock index 0ca0be50..eabd8900 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1206,15 +1206,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "cmake" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" -dependencies = [ - "cc", -] - [[package]] name = "colorchoice" version = "1.0.0" @@ -2766,6 +2757,16 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libmimalloc-sys" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3979b5c37ece694f1f5e51e7ecc871fdb0f517ed04ee45f88d15d6d553cb9664" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libredox" version = "0.0.1" @@ -2959,6 +2960,15 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "mimalloc" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa01922b5ea280a911e323e4d2fd24b7fe5cc4042e0d2cda3c40775cdc4bdc9c" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" @@ -4820,24 +4830,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" -[[package]] -name = "snmalloc-rs" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038507ad9c0ff0d6901e057494abcdba49a1a44fe3236f281730a9278166710d" -dependencies = [ - "snmalloc-sys", -] - -[[package]] -name = "snmalloc-sys" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cae3f7f662ebf11afe4d6534e63fa5846ec0143892c78ddb1040cc01249f143" -dependencies = [ - "cmake", -] - [[package]] name = "socket2" version = "0.4.10" @@ -4989,6 +4981,7 @@ dependencies = [ "hyper", "ipnet", "jemallocator", + "mimalloc", "nix", "once_cell", "opentelemetry", @@ -5004,7 +4997,6 @@ dependencies = [ "serde_cbor", "serde_json", "serial_test", - "snmalloc-rs", "surrealdb", "temp-env", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 7f9564d8..c76e3dd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,7 @@ uuid = { version = "1.6.1", features = ["serde", "js", "v4", "v7"] } nix = "0.26.4" [target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "ios"))'.dependencies] -snmalloc-rs = "0.3.4" +mimalloc = { version = "0.1.39", default-features = false } [target.'cfg(any(target_os = "android", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies] jemallocator = "0.5.4" diff --git a/src/mem/mod.rs b/src/mem/mod.rs index 73a05dbd..2ee2aa34 100644 --- a/src/mem/mod.rs +++ b/src/mem/mod.rs @@ -8,15 +8,15 @@ pub static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; #[cfg(target_os = "ios")] #[global_allocator] -pub static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; +pub static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; #[cfg(target_os = "linux")] #[global_allocator] -pub static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; +pub static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; #[cfg(target_os = "macos")] #[global_allocator] -pub static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; +pub static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; #[cfg(target_os = "netbsd")] #[global_allocator]