From d3f64742df2c8cec07f82ded9c8b6a2598b8af64 Mon Sep 17 00:00:00 2001 From: monosans Date: Tue, 30 Sep 2025 14:40:44 +0300 Subject: [PATCH] fix: add more allocator choices --- .github/workflows/ci.yml | 14 +++++++++----- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 10 ++++++++-- Dockerfile | 2 +- src/main.rs | 16 +++++++++------- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fac323..4ea1fb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -246,9 +246,9 @@ jobs: env: RUSTFLAGS: "" - if: ${{ matrix.cross }} - run: cross +beta build --features mimalloc,tui --release --target '${{ matrix.target }}' --locked + run: cross +beta build --features mimalloc_v3,tui --release --target '${{ matrix.target }}' --locked - if: ${{ !matrix.cross }} - run: cargo +beta build --features mimalloc,tui --release --target '${{ matrix.target }}' --locked + run: cargo +beta build --features mimalloc_v3,tui --release --target '${{ matrix.target }}' --locked - run: mkdir dist - run: echo -n '${{ github.sha }}' > dist/commit-sha.txt shell: bash @@ -410,7 +410,7 @@ jobs: target: ${{ matrix.target }} components: clippy cache-key: x86_64-unknown-linux-gnu - - run: cargo +beta clippy --all-targets ${{ matrix.features }} + - run: cargo +beta clippy ${{ matrix.features }} pre-commit: runs-on: ubuntu-24.04 steps: @@ -437,6 +437,11 @@ jobs: - run: cargo +nightly fmt --check udeps: runs-on: ubuntu-24.04 + strategy: + matrix: + features: + - "" + - "--features tui" steps: - uses: actions/checkout@v5 with: @@ -446,5 +451,4 @@ jobs: toolchain: nightly cache-key: x86_64-unknown-linux-gnu - run: cargo +nightly install --locked cargo-udeps - - run: cargo +nightly udeps - - run: cargo +nightly udeps --features mimalloc,tui + - run: cargo +nightly udeps ${{ matrix.features }} diff --git a/Cargo.lock b/Cargo.lock index 7986710..b01bac3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1459,6 +1459,7 @@ dependencies = [ "rlimit", "serde", "serde_json", + "tikv-jemallocator", "tokio", "tokio-util", "toml", @@ -2124,6 +2125,26 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "tinystr" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index db77797..bcc2fbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,11 +55,17 @@ tui-logger = { version = "=0.17.4", features = [ url = "=2.5.7" [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.48", optional = true, features = ["v3"] } +mimalloc_v2 = { package = "mimalloc", version = "=0.1.48", optional = true } +mimalloc_v3 = { package = "mimalloc", version = "=0.1.48", optional = true, features = [ + "v3", +] } +tikv-jemallocator = { version = "0.6.0", optional = true } [features] dhat = ["dep:dhat"] -mimalloc = ["dep:mimalloc"] +jemalloc = ["dep:tikv-jemallocator"] +mimalloc_v2 = ["dep:mimalloc_v2"] +mimalloc_v3 = ["dep:mimalloc_v3"] tui = ["dep:crossterm", "dep:futures", "dep:ratatui", "dep:tui-logger"] [profile.release] diff --git a/Dockerfile b/Dockerfile index 735f6c8..2cd2905 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 --features mimalloc --release --locked \ + cargo build --features mimalloc_v3 --release --locked \ && cp target/release/proxy-scraper-checker . diff --git a/src/main.rs b/src/main.rs index 2618042..9f4caa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,12 +47,6 @@ clippy::unwrap_used )] -#[cfg(all(feature = "dhat", feature = "mimalloc"))] -compile_error!( - "Features 'dhat-heap' and 'mimalloc' are mutually exclusive. Enable only \ - one." -); - mod checker; mod config; #[cfg(feature = "tui")] @@ -80,7 +74,15 @@ use tracing_subscriber::{ static GLOBAL: dhat::Alloc = dhat::Alloc; #[cfg(all( - feature = "mimalloc", + feature = "jemalloc", + any(target_arch = "aarch64", target_arch = "x86_64"), + any(target_os = "linux", target_os = "macos", target_os = "windows"), +))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + +#[cfg(all( + any(feature = "mimalloc_v2", feature = "mimalloc_v3"), any(target_arch = "aarch64", target_arch = "x86_64"), any(target_os = "linux", target_os = "macos", target_os = "windows"), ))]