From a34acf92ca3f8df894cea7560a09c315e78da458 Mon Sep 17 00:00:00 2001 From: Almaz Date: Sun, 10 Aug 2025 16:47:59 +0000 Subject: [PATCH] perf: add mimalloc --- .github/workflows/ci.yml | 4 ++-- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 8 ++++++-- Dockerfile | 2 +- src/main.rs | 8 ++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b688ba6..0967c3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -245,9 +245,9 @@ jobs: env: RUSTFLAGS: "" - if: ${{ matrix.cross }} - run: cross +beta build --features tui --release --target '${{ matrix.target }}' --locked + run: cross +beta build --features mimalloc,tui --release --target '${{ matrix.target }}' --locked - if: ${{ !matrix.cross }} - run: cargo +beta build --features tui --release --target '${{ matrix.target }}' --locked + run: cargo +beta build --features mimalloc,tui --release --target '${{ matrix.target }}' --locked - run: mkdir dist - run: echo -n '${{ github.sha }}' > dist/commit-sha.txt shell: bash diff --git a/Cargo.lock b/Cargo.lock index 38401fe..e77e13d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,6 +1073,16 @@ version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +[[package]] +name = "libmimalloc-sys" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88cd67e9de251c1781dbe2f641a1a3ad66eaae831b8a2c38fbdc5ddae16d4d" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libredox" version = "0.1.9" @@ -1170,6 +1180,15 @@ dependencies = [ "libc", ] +[[package]] +name = "mimalloc" +version = "0.1.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1791cbe101e95af5764f06f20f6760521f7158f69dbf9d6baf941ee1bf6bc40" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" @@ -1334,6 +1353,7 @@ dependencies = [ "futures", "httpdate", "maxminddb", + "mimalloc", "parking_lot", "rand 0.9.2", "ratatui", diff --git a/Cargo.toml b/Cargo.toml index 44e0715..4bfefe1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,8 @@ tui-logger = { version = "=0.17.3", features = [ ], optional = true } url = "=2.5.4" -[features] -tui = ["dep:crossterm", "dep:futures", "dep:ratatui", "dep:tui-logger"] +[target.'cfg(all(any(target_arch = "aarch64", target_arch = "x86_64"), any(target_os = "linux", target_os = "macos", target_os = "windows")))'.dependencies] +mimalloc = { version = "=0.1.47", optional = true } [target.'cfg(not(target_os = "android"))'.dependencies] reqwest = { version = "=0.12.22", default-features = false, features = [ @@ -59,6 +59,10 @@ reqwest = { version = "=0.12.22", default-features = false, features = [ "system-proxy", ] } +[features] +mimalloc = ["dep:mimalloc"] +tui = ["dep:crossterm", "dep:futures", "dep:ratatui", "dep:tui-logger"] + [profile.release] strip = true lto = "fat" diff --git a/Dockerfile b/Dockerfile index 6329f4c..5a4b515 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN --mount=source=src,target=src \ --mount=source=Cargo.lock,target=Cargo.lock \ --mount=type=cache,target=/app/target,sharing=locked \ --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \ - cargo build --release --locked \ + cargo build --features mimalloc --release --locked \ && cp target/release/proxy-scraper-checker . diff --git a/src/main.rs b/src/main.rs index e433df7..83d0d02 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,6 +70,14 @@ use tracing_subscriber::{ layer::SubscriberExt as _, util::SubscriberInitExt as _, }; +#[cfg(all( + feature = "mimalloc", + any(target_arch = "aarch64", target_arch = "x86_64"), + any(target_os = "linux", target_os = "macos", target_os = "windows"), +))] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + fn create_logging_filter( config: &config::Config, ) -> tracing_subscriber::filter::Targets {