Skip to content

Commit 56dfa85

Browse files
perf: use of mimalloc
1 parent f4ece93 commit 56dfa85

File tree

8 files changed

+47
-1
lines changed

8 files changed

+47
-1
lines changed

frameworks/Rust/axum/Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/Rust/axum/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ socket2 = "0.5.8"
8181
hyper = { version = "1.5", features = ["server", "http1"] }
8282
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
8383
quick_cache = "0.6.9"
84+
mimalloc = "0.1.43"
8485

8586

8687
[profile.release]

frameworks/Rust/axum/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ mod server;
44
use axum::{http::StatusCode, response::IntoResponse, routing::get, Router};
55
use common::models::Message;
66
use dotenv::dotenv;
7+
use mimalloc::MiMalloc;
8+
9+
#[global_allocator]
10+
static GLOBAL: MiMalloc = MiMalloc;
711

812
#[cfg(not(feature = "simd-json"))]
913
use axum::Json;

frameworks/Rust/axum/src/main_mongo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ use mongodb::{
2323
};
2424
use rand::{rngs::SmallRng, thread_rng, Rng, SeedableRng};
2525
use yarte::Template;
26+
use mimalloc::MiMalloc;
27+
28+
#[global_allocator]
29+
static GLOBAL: MiMalloc = MiMalloc;
2630

2731
use common::{
2832
get_env,

frameworks/Rust/axum/src/main_mongo_raw.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ use axum::{
1717
extract::Query, http::StatusCode, response::IntoResponse, routing::get, Router,
1818
};
1919

20+
use mimalloc::MiMalloc;
21+
22+
#[global_allocator]
23+
static GLOBAL: MiMalloc = MiMalloc;
24+
2025
#[cfg(not(feature = "simd-json"))]
2126
use axum::Json;
2227
#[cfg(feature = "simd-json")]

frameworks/Rust/axum/src/main_pg.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use axum::{
77
use dotenv::dotenv;
88
use rand::{rngs::SmallRng, thread_rng, SeedableRng};
99
use yarte::Template;
10+
use mimalloc::MiMalloc;
11+
12+
#[global_allocator]
13+
static GLOBAL: MiMalloc = MiMalloc;
1014

1115
#[cfg(not(feature = "simd-json"))]
1216
use axum::Json;

frameworks/Rust/axum/src/main_pg_pool.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ use dotenv::dotenv;
1515
use futures_util::{stream::FuturesUnordered, TryStreamExt};
1616
use rand::{rngs::SmallRng, thread_rng, SeedableRng};
1717
use yarte::Template;
18+
use mimalloc::MiMalloc;
19+
20+
#[global_allocator]
21+
static GLOBAL: MiMalloc = MiMalloc;
1822

1923
mod server;
2024

frameworks/Rust/axum/src/main_sqlx.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use quick_cache::sync::Cache;
1616
use rand::{rngs::SmallRng, thread_rng, SeedableRng};
1717
use sqlx::models::World;
1818
use yarte::Template;
19+
use mimalloc::MiMalloc;
20+
21+
#[global_allocator]
22+
static GLOBAL: MiMalloc = MiMalloc;
1923

2024
#[cfg(not(feature = "simd-json"))]
2125
use axum::Json;
@@ -98,7 +102,7 @@ async fn cache(
98102
let count = parse_params(params);
99103
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
100104
let mut worlds: Vec<Option<World>> = Vec::with_capacity(count);
101-
105+
102106
for id in random_ids(&mut rng, count) {
103107
worlds.push(cache.get(&id));
104108
}

0 commit comments

Comments
 (0)