Skip to content

Commit

Permalink
Merge branch 'PyO3:main' into add-error-messages-for-unsupported-macr…
Browse files Browse the repository at this point in the history
…o-features-on-compilation
  • Loading branch information
cojmeister authored Mar 25, 2024
2 parents 3a39f8c + 7d319a9 commit 5bb7425
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 129 deletions.
42 changes: 32 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ jobs:
rust: [stable]
platform: [
{
os: "macos-latest",
python-architecture: "x64",
rust-target: "x86_64-apple-darwin",
os: "macos-14", # first available arm macos runner
python-architecture: "arm64",
rust-target: "aarch64-apple-darwin",
},
{
os: "ubuntu-latest",
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
rust-target: "x86_64-unknown-linux-gnu",
}
name: clippy/${{ matrix.platform.rust-target }}/${{ matrix.rust }}
continue-on-error: ${{ matrix.platform.rust != 'stable' }}
continue-on-error: ${{ matrix.rust != 'stable' }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
Expand Down Expand Up @@ -161,7 +161,12 @@ jobs:
platform:
[
{
os: "macos-latest",
os: "macos-14", # first available arm macos runner
python-architecture: "arm64",
rust-target: "aarch64-apple-darwin",
},
{
os: "macos-13", # last available x86_64 macos runner
python-architecture: "x64",
rust-target: "x86_64-apple-darwin",
},
Expand Down Expand Up @@ -226,8 +231,13 @@ jobs:
]
platform:
[
# for the full matrix, use x86_64 macos runners because not all Python versions
# PyO3 supports are available for arm on GitHub Actions. (Availability starts
# around Python 3.10, can switch the full matrix to arm once earlier versions
# are dropped.)
# NB: if this switches to arm, switch the arm job below in the `include` to x86_64
{
os: "macos-latest",
os: "macos-13",
python-architecture: "x64",
rust-target: "x86_64-apple-darwin",
},
Expand Down Expand Up @@ -287,6 +297,18 @@ jobs:
}
extra-features: "multiple-pymethods"

# test arm macos runner with the latest Python version
# NB: if the full matrix switchess to arm, switch to x86_64 here
- rust: stable
python-version: "3.12"
platform:
{
os: "macos-14",
python-architecture: "arm64",
rust-target: "aarch64-apple-darwin",
}
extra-features: "multiple-pymethods"

valgrind:
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
needs: [fmt]
Expand Down Expand Up @@ -343,13 +365,13 @@ jobs:

coverage:
needs: [fmt]
name: coverage-${{ matrix.os }}
name: coverage ${{ matrix.os }}
strategy:
matrix:
os: ["windows", "macos", "ubuntu"]
runs-on: ${{ matrix.os }}-latest
os: ["windows-latest", "macos-14", "ubuntu-latest"] # first available arm macos runner
runs-on: ${{ matrix.os }}
steps:
- if: ${{ github.event_name == 'pull_request' && matrix.os != 'ubuntu' }}
- if: ${{ github.event_name == 'pull_request' && matrix.os != 'ubuntu-latest' }}
id: should-skip
shell: bash
run: echo 'skip=true' >> $GITHUB_OUTPUT
Expand Down
34 changes: 10 additions & 24 deletions pyo3-benches/benches/bench_bigint.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use std::hint::black_box;

use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};
use num_bigint::BigInt;

use pyo3::prelude::*;
use pyo3::types::PyDict;

use num_bigint::BigInt;

fn extract_bigint_extract_fail(bench: &mut Bencher<'_>) {
Python::with_gil(|py| {
let d = PyDict::new_bound(py).into_any();

bench.iter(|| match black_box(&d).extract::<BigInt>() {
Ok(v) => panic!("should err {}", v),
Err(e) => black_box(e),
Err(e) => e,
});
});
}
Expand All @@ -20,54 +21,39 @@ fn extract_bigint_small(bench: &mut Bencher<'_>) {
Python::with_gil(|py| {
let int = py.eval_bound("-42", None, None).unwrap();

bench.iter(|| {
let v = black_box(&int).extract::<BigInt>().unwrap();
black_box(v);
});
bench.iter_with_large_drop(|| black_box(&int).extract::<BigInt>().unwrap());
});
}

fn extract_bigint_big_negative(bench: &mut Bencher<'_>) {
Python::with_gil(|py| {
let int = py.eval_bound("-10**300", None, None).unwrap();

bench.iter(|| {
let v = black_box(&int).extract::<BigInt>().unwrap();
black_box(v);
});
bench.iter_with_large_drop(|| black_box(&int).extract::<BigInt>().unwrap());
});
}

fn extract_bigint_big_positive(bench: &mut Bencher<'_>) {
Python::with_gil(|py| {
let int = py.eval_bound("10**300", None, None).unwrap();

bench.iter(|| {
let v = black_box(&int).extract::<BigInt>().unwrap();
black_box(v);
});
bench.iter_with_large_drop(|| black_box(&int).extract::<BigInt>().unwrap());
});
}

fn extract_bigint_huge_negative(bench: &mut Bencher<'_>) {
Python::with_gil(|py| {
let int = py.eval_bound("-10**3000", None, None).unwrap();

bench.iter(|| {
let v = black_box(&int).extract::<BigInt>().unwrap();
black_box(v);
});
bench.iter_with_large_drop(|| black_box(&int).extract::<BigInt>().unwrap());
});
}

fn extract_bigint_huge_positive(bench: &mut Bencher<'_>) {
Python::with_gil(|py| {
let int = py.eval_bound("10**3000", None, None).unwrap();

bench.iter(|| {
let v = black_box(&int).extract::<BigInt>().unwrap();
black_box(v);
});
bench.iter_with_large_drop(|| black_box(&int).extract::<BigInt>().unwrap());
});
}

Expand Down
10 changes: 5 additions & 5 deletions pyo3-benches/benches/bench_decimal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use std::hint::black_box;

use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};
use rust_decimal::Decimal;

use pyo3::prelude::*;
use pyo3::types::PyDict;
use rust_decimal::Decimal;

fn decimal_via_extract(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
Expand All @@ -18,9 +20,7 @@ py_dec = decimal.Decimal("0.0")
.unwrap();
let py_dec = locals.get_item("py_dec").unwrap().unwrap();

b.iter(|| {
let _: Decimal = black_box(&py_dec).extract().unwrap();
});
b.iter(|| black_box(&py_dec).extract::<Decimal>().unwrap());
})
}

Expand Down
10 changes: 4 additions & 6 deletions pyo3-benches/benches/bench_dict.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::collections::{BTreeMap, HashMap};
use std::hint::black_box;

use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};

use pyo3::types::IntoPyDict;
use pyo3::{prelude::*, types::PyMapping};
use std::collections::{BTreeMap, HashMap};
use std::hint::black_box;

fn iter_dict(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
Expand Down Expand Up @@ -69,7 +70,6 @@ fn extract_hashbrown_map(b: &mut Bencher<'_>) {
});
}

#[cfg(not(codspeed))]
fn mapping_from_dict(b: &mut Bencher<'_>) {
Python::with_gil(|py| {
const LEN: usize = 100_000;
Expand All @@ -84,12 +84,10 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("dict_get_item", dict_get_item);
c.bench_function("extract_hashmap", extract_hashmap);
c.bench_function("extract_btreemap", extract_btreemap);
c.bench_function("mapping_from_dict", mapping_from_dict);

#[cfg(feature = "hashbrown")]
c.bench_function("extract_hashbrown_map", extract_hashbrown_map);

#[cfg(not(codspeed))]
c.bench_function("mapping_from_dict", mapping_from_dict);
}

criterion_group!(benches, criterion_benchmark);
Expand Down
Loading

0 comments on commit 5bb7425

Please sign in to comment.