Skip to content

Commit

Permalink
Replace MiMalloc w/ default allocator (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Aug 18, 2023
1 parent 5f7426d commit ce2068f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 47 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci.yml
Expand Up @@ -396,14 +396,11 @@ jobs:
- os: ubuntu
platform: linux
target: aarch64
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features

- os: ubuntu
platform: linux
target: armv7
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features
# musllinux
- os: ubuntu
platform: linux
Expand All @@ -417,14 +414,10 @@ jobs:
platform: linux
target: ppc64le
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features
- os: ubuntu
platform: linux
target: s390x
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features
exclude:
# Optimized PGO builds for x86_64 manylinux and windows follow a different matrix,
# maybe in future maturin-action can support this automatically
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/codspeed.yml
Expand Up @@ -50,10 +50,8 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Compile pydantic-core for profiling
# --no-default-features to avoid using mimalloc
run: |
pip install -e . --config-settings=build-args='--no-default-features --verbose' -v
python -c 'import pydantic_core; assert pydantic_core._pydantic_core.__pydantic_core_default_allocator__'
pip install -e . --config-settings=build-args='--verbose' -v
env:
CONST_RANDOM_SEED: 0 # Fix the compile time RNG seed
RUSTFLAGS: "-Cprofile-generate=${{ github.workspace }}/profdata"
Expand All @@ -65,10 +63,8 @@ jobs:
run: rustup run stable bash -c '$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata'

- name: Compile pydantic-core for benchmarking
# --no-default-features to avoid using mimalloc
run: |
pip install -e . --config-settings=build-args='--no-default-features --verbose' -v
python -c 'import pydantic_core; assert pydantic_core._pydantic_core.__pydantic_core_default_allocator__'
pip install -e . --config-settings=build-args='--verbose' -v
env:
CONST_RANDOM_SEED: 0 # Fix the compile time RNG seed
RUSTFLAGS: "-Cprofile-use=${{ github.workspace }}/merged.profdata"
Expand Down
20 changes: 0 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Expand Up @@ -33,8 +33,6 @@ strum_macros = "0.25.2"
serde_json = {version = "1.0.104", features = ["arbitrary_precision", "preserve_order"]}
enum_dispatch = "0.3.8"
serde = { version = "1.0.183", features = ["derive"] }
# disabled for benchmarks since it makes microbenchmark performance more flakey
mimalloc = { version = "0.1.30", optional = true, default-features = false, features = ["local_dynamic_tls"] }
speedate = "0.12.0"
smallvec = "1.11.0"
ahash = "0.8.0"
Expand All @@ -53,7 +51,6 @@ crate-type = ["cdylib", "rlib"]
[features]
# must be enabled when building with `cargo build`, maturin enables this automatically
extension-module = ["pyo3/extension-module"]
default = ["mimalloc"]

[profile.release]
lto = "fat"
Expand Down
11 changes: 1 addition & 10 deletions src/lib.rs
Expand Up @@ -6,10 +6,6 @@ use std::sync::OnceLock;

use pyo3::{prelude::*, sync::GILOnceCell};

#[cfg(feature = "mimalloc")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

// parse this first to get access to the contained macro
#[macro_use]
mod py_gc;
Expand Down Expand Up @@ -69,10 +65,9 @@ fn get_pydantic_version(py: Python<'_>) -> Option<&'static str> {

pub fn build_info() -> String {
format!(
"profile={} pgo={} mimalloc={}",
"profile={} pgo={}",
env!("PROFILE"),
option_env!("RUSTFLAGS").unwrap_or("").contains("-Cprofile-use="),
cfg!(feature = "mimalloc")
)
}

Expand Down Expand Up @@ -102,9 +97,5 @@ fn _pydantic_core(py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(to_json, m)?)?;
m.add_function(wrap_pyfunction!(to_jsonable_python, m)?)?;
m.add_function(wrap_pyfunction!(list_all_errors, m)?)?;

#[cfg(not(feature = "mimalloc"))]
m.setattr("__pydantic_core_default_allocator__", true)?; // uses setattr so this is not in __all__

Ok(())
}

0 comments on commit ce2068f

Please sign in to comment.