From 3052bf20a22ee3d45b8fab515e7814fdfeb16635 Mon Sep 17 00:00:00 2001 From: clux Date: Sun, 19 May 2024 16:50:39 +0100 Subject: [PATCH] Add hints about changing allocators references #142 and does it in one example Signed-off-by: clux --- README.md | 13 +++++++++++++ test/serdecrate/Cargo.toml | 2 ++ test/serdecrate/src/main.rs | 9 +++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d98b67b..c6da6d8 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,19 @@ CircleCI supports both methods: - [Circle: direct folder cache (manual docker build)](https://github.com/clux/webapp-rs/blob/master/.circleci/config.yml) - Circle also supports [docker layer caching](https://circleci.com/docs/2.0/docker-layer-caching/) (no example atm) +## Allocator Performance + +To optimise memory performance (see [#142](https://github.com/clux/muslrust/issues/142)) consider changing the global allocators in sensitive applications: + +- [jemalloc](https://github.com/tikv/jemallocator) +- [mimalloc](https://github.com/microsoft/mimalloc) + +```rust +use tikv_jemallocator::Jemalloc; +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; +``` + ## Troubleshooting ### SSL Verification diff --git a/test/serdecrate/Cargo.toml b/test/serdecrate/Cargo.toml index 0b56f19..e98b8e9 100644 --- a/test/serdecrate/Cargo.toml +++ b/test/serdecrate/Cargo.toml @@ -2,8 +2,10 @@ authors = ["clux "] name = "serdecrate" version = "0.1.0" +edition = "2021" [dependencies] serde = "1.0.15" serde_derive = "1.0.15" serde_json = "1.0.4" +tikv-jemallocator = "0.5.4" diff --git a/test/serdecrate/src/main.rs b/test/serdecrate/src/main.rs index 3ce6b2e..527175d 100644 --- a/test/serdecrate/src/main.rs +++ b/test/serdecrate/src/main.rs @@ -1,8 +1,9 @@ -#[macro_use] -extern crate serde_derive; +use serde_derive::{Deserialize, Serialize}; +use serde_json; -extern crate serde; -extern crate serde_json; +use tikv_jemallocator::Jemalloc; +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; #[derive(Serialize, Deserialize, Debug)] struct Point {