Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions Cargo.lock

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

12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rust-version = "1.75"
[dependencies]
# TODO it would be very nice to remove the "py-clone" feature as it can panic,
# but needs a bit of work to make sure it's not used in the codebase
pyo3 = { version = "0.25", features = ["generate-import-lib", "num-bigint", "py-clone"] }
pyo3 = { version = "0.26", features = ["generate-import-lib", "num-bigint", "py-clone"] }
regex = "1.11.1"
strum = { version = "0.27", features = ["derive"] }
strum_macros = "0.27"
Expand All @@ -44,17 +44,13 @@ base64 = "0.22.1"
num-bigint = "0.4.6"
num-traits = "0.2.19"
uuid = "1.17.0"
jiter = { version = "0.10.0", features = ["python"] }
jiter = { version = "0.11.0", features = ["python"] }
hex = "0.4.3"

[lib]
name = "_pydantic_core"
crate-type = ["cdylib", "rlib"]

[features]
# must be enabled when building with `cargo build`, maturin enables this automatically
extension-module = ["pyo3/extension-module"]

[profile.release]
lto = "fat"
codegen-units = 1
Expand All @@ -72,12 +68,12 @@ debug = true
strip = false

[dev-dependencies]
pyo3 = { version = "0.25", features = ["auto-initialize"] }
pyo3 = { version = "0.26", features = ["auto-initialize"] }

[build-dependencies]
version_check = "0.9.5"
# used where logic has to be version/distribution specific, e.g. pypy
pyo3-build-config = { version = "0.25" }
pyo3-build-config = { version = "0.26" }

[lints.clippy]
dbg_macro = "warn"
Expand Down
58 changes: 29 additions & 29 deletions benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn json<'a>(py: Python<'a>, code: &'a str) -> Bound<'a, PyAny> {

#[bench]
fn ints_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'int'}");

let result = validator
Expand All @@ -50,7 +50,7 @@ fn ints_json(bench: &mut Bencher) {

#[bench]
fn ints_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'int'}");

let Ok(input) = 123_i64.into_pyobject(py);
Expand All @@ -73,7 +73,7 @@ fn ints_python(bench: &mut Bencher) {

#[bench]
fn list_int_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'list', 'items_schema': {'type': 'int'}}");
let code = format!(
"[{}]",
Expand Down Expand Up @@ -104,7 +104,7 @@ fn list_int_input(py: Python<'_>) -> (SchemaValidator, PyObject) {

#[bench]
fn list_int_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let (validator, input) = list_int_input(py);
let input = black_box(input.bind(py));
bench.iter(|| {
Expand All @@ -118,7 +118,7 @@ fn list_int_python(bench: &mut Bencher) {

#[bench]
fn list_int_python_isinstance(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let (validator, input) = list_int_input(py);
let input = black_box(input.bind(py));
let v = validator
Expand All @@ -137,7 +137,7 @@ fn list_int_python_isinstance(bench: &mut Bencher) {

#[bench]
fn list_error_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'list', 'items_schema': {'type': 'int'}}");
let code = format!(
"[{}]",
Expand Down Expand Up @@ -195,7 +195,7 @@ fn list_error_python_input(py: Python<'_>) -> (SchemaValidator, PyObject) {

#[bench]
fn list_error_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let (validator, input) = list_error_python_input(py);

let input = black_box(input.bind(py));
Expand All @@ -212,7 +212,7 @@ fn list_error_python(bench: &mut Bencher) {

#[bench]
fn list_error_python_isinstance(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let (validator, input) = list_error_python_input(py);
let input = black_box(input.bind(py));
let r = validator
Expand All @@ -232,7 +232,7 @@ fn list_error_python_isinstance(bench: &mut Bencher) {

#[bench]
fn list_any_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'list'}");
let code = format!(
"[{}]",
Expand All @@ -251,7 +251,7 @@ fn list_any_json(bench: &mut Bencher) {

#[bench]
fn list_any_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'list'}");
let code = CString::new(format!(
"[{}]",
Expand Down Expand Up @@ -279,7 +279,7 @@ fn as_str(i: u8) -> String {

#[bench]
fn dict_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
c"{'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': {'type': 'int'}}",
Expand All @@ -305,7 +305,7 @@ fn dict_json(bench: &mut Bencher) {

#[bench]
fn dict_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
c"{'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': {'type': 'int'}}",
Expand All @@ -332,7 +332,7 @@ fn dict_python(bench: &mut Bencher) {

#[bench]
fn dict_value_error(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
cr"{
Expand Down Expand Up @@ -378,7 +378,7 @@ fn dict_value_error(bench: &mut Bencher) {

#[bench]
fn typed_dict_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
cr"{
Expand Down Expand Up @@ -413,7 +413,7 @@ fn typed_dict_json(bench: &mut Bencher) {

#[bench]
fn typed_dict_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
cr"{
Expand Down Expand Up @@ -448,7 +448,7 @@ fn typed_dict_python(bench: &mut Bencher) {

#[bench]
fn typed_dict_deep_error(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
cr"{
Expand Down Expand Up @@ -504,7 +504,7 @@ fn typed_dict_deep_error(bench: &mut Bencher) {

#[bench]
fn complete_model(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let sys_path = py.import("sys").unwrap().getattr("path").unwrap();
sys_path.call_method1("append", ("./tests/benchmarks/",)).unwrap();

Expand All @@ -527,7 +527,7 @@ fn complete_model(bench: &mut Bencher) {

#[bench]
fn nested_model_using_definitions(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let sys_path = py.import("sys").unwrap().getattr("path").unwrap();
sys_path.call_method1("append", ("./tests/benchmarks/",)).unwrap();

Expand All @@ -554,7 +554,7 @@ fn nested_model_using_definitions(bench: &mut Bencher) {

#[bench]
fn nested_model_inlined(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let sys_path = py.import("sys").unwrap().getattr("path").unwrap();
sys_path.call_method1("append", ("./tests/benchmarks/",)).unwrap();

Expand All @@ -581,7 +581,7 @@ fn nested_model_inlined(bench: &mut Bencher) {

#[bench]
fn literal_ints_few_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'literal', 'expected': list(range(5))}");

let Ok(input) = 4_i64.into_pyobject(py);
Expand All @@ -604,7 +604,7 @@ fn literal_ints_few_python(bench: &mut Bencher) {

#[bench]
fn literal_strings_few_small_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'literal', 'expected': [f'{idx}' for idx in range(5)]}");

let input = py.eval(c"'4'", None, None).unwrap();
Expand All @@ -628,7 +628,7 @@ fn literal_strings_few_small_python(bench: &mut Bencher) {

#[bench]
fn literal_strings_few_large_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(5)]}",
Expand All @@ -655,7 +655,7 @@ fn literal_strings_few_large_python(bench: &mut Bencher) {

#[bench]
fn literal_enums_few_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let globals = PyDict::new(py);
py.run(
cr"
Expand Down Expand Up @@ -697,7 +697,7 @@ class Foo(Enum):

#[bench]
fn literal_ints_many_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'literal', 'expected': list(range(100))}");

let Ok(input) = 99_i64.into_pyobject(py);
Expand All @@ -720,7 +720,7 @@ fn literal_ints_many_python(bench: &mut Bencher) {

#[bench]
fn literal_strings_many_small_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator =
build_schema_validator(py, c"{'type': 'literal', 'expected': [f'{idx}' for idx in range(100)]}");

Expand All @@ -745,7 +745,7 @@ fn literal_strings_many_small_python(bench: &mut Bencher) {

#[bench]
fn literal_strings_many_large_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(100)]}",
Expand All @@ -772,7 +772,7 @@ fn literal_strings_many_large_python(bench: &mut Bencher) {

#[bench]
fn literal_ints_many_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(py, c"{'type': 'literal', 'expected': list(range(100))}");

let input_json = py.eval(c"'99'", None, None).unwrap();
Expand All @@ -795,7 +795,7 @@ fn literal_ints_many_json(bench: &mut Bencher) {

#[bench]
fn literal_strings_many_large_json(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let validator = build_schema_validator(
py,
c"{'type': 'literal', 'expected': ['a' * 25 + f'{idx}' for idx in range(100)]}",
Expand Down Expand Up @@ -823,7 +823,7 @@ fn literal_strings_many_large_json(bench: &mut Bencher) {

#[bench]
fn literal_mixed_few_python(bench: &mut Bencher) {
Python::with_gil(|py| {
Python::attach(|py| {
let globals = PyDict::new(py);
py.run(
cr"
Expand Down
Loading
Loading