From 52de19afd6dc7b84b61214816ade63a87fa08dcf Mon Sep 17 00:00:00 2001 From: Giovanni Barillari Date: Fri, 27 Jun 2025 19:24:14 +0200 Subject: [PATCH] Gate jemalloc behind feature (#618) --- .github/workflows/build.yml | 27 ++++++--------------------- .github/workflows/release.yml | 27 ++++++--------------------- .github/workflows/test.yml | 24 +++++++++++++++++------- Cargo.toml | 5 ++--- src/lib.rs | 10 ++-------- 5 files changed, 33 insertions(+), 60 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 05f4778..764323d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,10 +11,10 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu, macos, windows] + os: [ubuntu, macos] target: [x86_64, aarch64] manylinux: [auto] - allocator: [auto] + allocator: [jemalloc] include: - os: ubuntu platform: linux @@ -29,6 +29,7 @@ jobs: platform: linux target: i686 interpreter: 3.9 3.10 3.11 3.12 3.13 3.14 + allocator: jemalloc - os: ubuntu platform: linux target: aarch64 @@ -46,6 +47,7 @@ jobs: platform: linux target: armv7 interpreter: 3.9 3.10 3.11 3.12 3.13 3.14 + allocator: jemalloc - os: ubuntu platform: linux target: x86_64 @@ -77,14 +79,8 @@ jobs: allocator: mimalloc - os: windows target: x86_64 - interpreter: 3.9 3.10 3.11 3.12 3.13 3.14 pypy3.9 pypy3.10 pypy3.11 - - os: windows - target: x86_64 - interpreter: 3.13t 3.14t + interpreter: 3.9 3.10 3.11 3.12 3.13 3.13t 3.14 3.14t pypy3.9 pypy3.10 pypy3.11 allocator: mimalloc - exclude: - - os: windows - target: aarch64 runs-on: ${{ matrix.os }}-latest steps: @@ -94,21 +90,10 @@ jobs: run: | echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV - uses: pyo3/maturin-action@v1 - if: matrix.allocator != 'mimalloc' with: rust-toolchain: stable command: build - args: --release --out dist --interpreter ${{ matrix.interpreter || env.PY_ALL }} - target: ${{ matrix.target }} - manylinux: ${{ matrix.manylinux || 'auto' }} - container: ${{ matrix.container }} - docker-options: -e CI - - uses: pyo3/maturin-action@v1 - if: matrix.allocator == 'mimalloc' - with: - rust-toolchain: stable - command: build - args: --release --out dist --features mimalloc --interpreter ${{ matrix.interpreter || env.PY_ALL }} + args: --release --out dist --features ${{ matrix.allocator }} --interpreter ${{ matrix.interpreter || env.PY_ALL }} target: ${{ matrix.target }} manylinux: ${{ matrix.manylinux || 'auto' }} container: ${{ matrix.container }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad16956..d33efc5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,10 +30,10 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu, macos, windows] + os: [ubuntu, macos] target: [x86_64, aarch64] manylinux: [auto] - allocator: [auto] + allocator: [jemalloc] include: - os: ubuntu platform: linux @@ -48,6 +48,7 @@ jobs: platform: linux target: i686 interpreter: 3.9 3.10 3.11 3.12 3.13 3.14 + allocator: jemalloc - os: ubuntu platform: linux target: aarch64 @@ -65,6 +66,7 @@ jobs: platform: linux target: armv7 interpreter: 3.9 3.10 3.11 3.12 3.13 3.14 + allocator: jemalloc - os: ubuntu platform: linux target: x86_64 @@ -96,14 +98,8 @@ jobs: allocator: mimalloc - os: windows target: x86_64 - interpreter: 3.9 3.10 3.11 3.12 3.13 3.14 pypy3.9 pypy3.10 pypy3.11 - - os: windows - target: x86_64 - interpreter: 3.13t 3.14t + interpreter: 3.9 3.10 3.11 3.12 3.13 3.13t 3.14 3.14t pypy3.9 pypy3.10 pypy3.11 allocator: mimalloc - exclude: - - os: windows - target: aarch64 runs-on: ${{ matrix.os }}-latest steps: @@ -113,21 +109,10 @@ jobs: run: | echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV - uses: pyo3/maturin-action@v1 - if: matrix.allocator != 'mimalloc' with: rust-toolchain: stable command: build - args: --release --out dist --interpreter ${{ matrix.interpreter || env.PY_ALL }} - target: ${{ matrix.target }} - manylinux: ${{ matrix.manylinux || 'auto' }} - container: ${{ matrix.container }} - docker-options: -e CI - - uses: pyo3/maturin-action@v1 - if: matrix.allocator == 'mimalloc' - with: - rust-toolchain: stable - command: build - args: --release --out dist --features mimalloc --interpreter ${{ matrix.interpreter || env.PY_ALL }} + args: --release --out dist --features ${{ matrix.allocator }} --interpreter ${{ matrix.interpreter || env.PY_ALL }} target: ${{ matrix.target }} manylinux: ${{ matrix.manylinux || 'auto' }} container: ${{ matrix.container }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8f347ca..9581bf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,20 +11,25 @@ on: jobs: linux: + name: linux (${{ matrix.python-version }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: + allocator: [jemalloc] python-version: - '3.9' - '3.10' - '3.11' - '3.12' - '3.13' - - '3.13t' - '3.14' - - '3.14t' - pypy3.11 + include: + - python-version: 3.13t + allocator: mimalloc + - python-version: 3.14t + allocator: mimalloc env: UV_PYTHON: ${{ matrix.python-version }} @@ -38,26 +43,31 @@ jobs: uv python install ${{ env.UV_PYTHON }} uv venv .venv uv sync --group all - uv run --no-sync maturin develop --uv + uv run --no-sync maturin develop --uv --features ${{ matrix.allocator }} - name: Test run: | source .venv/bin/activate make test macos: + name: macos (${{ matrix.python-version }}) runs-on: macos-latest strategy: fail-fast: false matrix: + allocator: [jemalloc] python-version: - '3.9' - '3.10' - '3.11' - '3.12' - '3.13' - - '3.13t' - '3.14' - - '3.14t' + include: + - python-version: 3.13t + allocator: mimalloc + - python-version: 3.14t + allocator: mimalloc env: UV_PYTHON: ${{ matrix.python-version }} @@ -71,7 +81,7 @@ jobs: uv python install ${{ env.UV_PYTHON }} uv venv .venv uv sync --group all - uv run --no-sync maturin develop --uv + uv run --no-sync maturin develop --uv --features ${{ matrix.allocator }} - name: Test run: | source .venv/bin/activate @@ -104,7 +114,7 @@ jobs: uv python install ${{ env.UV_PYTHON }} uv venv .venv uv sync --group all - uv run --no-sync maturin develop --uv + uv run --no-sync maturin develop --uv --features mimalloc - name: Test run: | uv run --no-sync pytest -v tests diff --git a/Cargo.toml b/Cargo.toml index 6ec8860..75906fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,19 +50,18 @@ pyo3 = { version = "=0.25", features = ["anyhow", "extension-module", "generate- pyo3-log = "=0.12" rustls-pemfile = "2.2" socket2 = { version = "=0.5.10", features = ["all"] } +tikv-jemallocator = { version = "0.6.0", default-features = false, features = ["disable_initial_exec_tls"], optional = true } tls-listener = { version = "=0.11", features = ["rustls-ring"] } tokio = { version = "1.45", features = ["full"] } tokio-stream = "0.1" tokio-tungstenite = "=0.26" tokio-util = { version = "0.7", features = ["codec", "rt"] } -[target.'cfg(not(any(target_env = "musl", target_os = "freebsd", target_os = "openbsd", target_os = "windows")))'.dependencies] -tikv-jemallocator = { version = "0.6.0", default-features = false, features = ["disable_initial_exec_tls"] } - [build-dependencies] pyo3-build-config = "=0.25" [features] +jemalloc = ["dep:tikv-jemallocator"] mimalloc = ["dep:mimalloc"] [profile.release] diff --git a/src/lib.rs b/src/lib.rs index 9172842..692252d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,8 @@ -#[cfg(not(any( - target_env = "musl", - target_os = "freebsd", - target_os = "openbsd", - target_os = "windows", - feature = "mimalloc" -)))] +#[cfg(all(feature = "jemalloc", not(feature = "mimalloc")))] #[global_allocator] static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; -#[cfg(feature = "mimalloc")] +#[cfg(all(feature = "mimalloc", not(feature = "jemalloc")))] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;