Skip to content

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runkle sydney-runkle commented Jan 15, 2025

This results in solid perf improvements (5-10% ish) for schema builds, which we're actively focused on.

You can now enable this with PYDANTIC_VALIDATE_CORE_SCHEMAS if you're having issues with custom schemas.
If issues are struggling with this, it's a sign that we need to fix things in pydantic-core validator builds.

@sydney-runkle sydney-runkle added the relnotes-performance Used for performance improvements. label Jan 15, 2025
Copy link

codspeed-hq bot commented Jan 15, 2025

CodSpeed Performance Report

Merging #11271 will improve performances by 10.25%

Comparing remove-schema-val (4204a07) with main (42b9328)

Summary

⚡ 14 improvements
✅ 31 untouched benchmarks

Benchmarks breakdown

Benchmark main remove-schema-val Change
test_fastapi_startup_perf 214.8 ms 200.5 ms +7.14%
test_complex_model_schema_generation 1.9 ms 1.8 ms +5.3%
test_construct_dataclass_schema 2 ms 1.8 ms +9.58%
test_nested_model_schema_generation 1.2 ms 1.1 ms +8.63%
test_recursive_model_schema_generation 1.1 ms 1 ms +6.58%
test_simple_model_schema_generation 800.8 µs 744.3 µs +7.59%
test_tagged_union_with_callable_discriminator_schema_generation 1.6 ms 1.5 ms +10.25%
test_tagged_union_with_str_discriminator_schema_generation 1.7 ms 1.6 ms +9.11%
test_deeply_nested_recursive_model_schema_generation 1.4 ms 1.3 ms +6.18%
test_generic_recursive_model_schema_generation 954.1 µs 892.1 µs +6.95%
test_nested_recursive_generic_model_schema_generation 1.8 ms 1.7 ms +6.89%
test_nested_recursive_model_schema_generation 1.9 ms 1.8 ms +6.28%
test_recursive_discriminated_union_with_base_model 1.8 ms 1.7 ms +5.85%
test_simple_recursive_model_schema_generation 845.2 µs 773.8 µs +9.22%

Copy link

cloudflare-workers-and-pages bot commented Jan 15, 2025

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4204a07
Status: ✅  Deploy successful!
Preview URL: https://bceef31d.pydantic-docs.pages.dev
Branch Preview URL: https://remove-schema-val.pydantic-docs.pages.dev

View logs

@sydney-runkle sydney-runkle marked this pull request as ready for review January 15, 2025 11:35
Copy link
Contributor

github-actions bot commented Jan 15, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  json_schema.py
  pydantic/_internal
  _core_utils.py 605
Project Total  

This report was generated by python-coverage-comment-action

@sydney-runkle sydney-runkle added the relnotes-change Used for changes to existing functionality which don't have a better categorization. label Jan 15, 2025
@sydney-runkle sydney-runkle changed the title Draft: Remove pydantic-core schema validation Remove pydantic-core schema validation Jan 15, 2025
@Viicos
Copy link
Member

Viicos commented Jan 16, 2025

What happens with the example I provided on Slack?

@sydney-runkle
Copy link
Contributor Author

sydney-runkle commented Jan 16, 2025

@Viicos,

It doesn't error:

from pydantic import TypeAdapter, Strict
from typing import Annotated
from collections.abc import Iterable

ta = TypeAdapter(Annotated[Iterable[int], Strict()])
print(ta.core_schema)
# > {'type': 'generator', 'items_schema': {'type': 'int'}, 'strict': True}

print(ta.validate_python(['1', '2', '3']))
# > ValidatorIterator(index=0, schema=Some(Int(IntValidator { strict: false })))

You're right, the error on main is more helpful, this is something we should probably enforce in core.

Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
@Viicos Viicos changed the title Remove pydantic-core schema validation Disable pydantic-core core schema validation Jan 21, 2025
@sydney-runkle sydney-runkle merged commit 1c698d7 into main Jan 21, 2025
56 checks passed
@sydney-runkle sydney-runkle deleted the remove-schema-val branch January 21, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-change Used for changes to existing functionality which don't have a better categorization. relnotes-performance Used for performance improvements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants