Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move enum validation and serialization to Rust #9064

Merged
merged 11 commits into from Mar 25, 2024
Merged

Conversation

samuelcolvin
Copy link
Member

Change Summary

Sequel to pydantic/pydantic-core#1235, should give a 4x+ speedup to enum validation.

This will fail until we make a new pydantic-core release.

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@samuelcolvin samuelcolvin marked this pull request as draft March 20, 2024 18:06
Copy link

cloudflare-pages bot commented Mar 20, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9d42245
Status: ✅  Deploy successful!
Preview URL: https://e2d623f1.pydantic-docs2.pages.dev
Branch Preview URL: https://rust-enum-validation.pydantic-docs2.pages.dev

View logs

elif types == {bool}:
result['type'] = 'boolean'
elif types == {list}:
result['type'] = 'array'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably need a test to check that tuple values generate the right schema.

Copy link

codspeed-hq bot commented Mar 20, 2024

CodSpeed Performance Report

Merging #9064 will improve performances by 30.01%

Comparing rust-enum-validation (9d42245) with main (d6ca333)

Summary

⚡ 3 improvements
✅ 7 untouched benchmarks

Benchmarks breakdown

Benchmark main rust-enum-validation Change
test_north_star_dump_json 202.4 ms 180.9 ms +11.9%
test_north_star_validate_json 335 ms 258.3 ms +29.7%
test_north_star_validate_json_strict 334.6 ms 257.4 ms +30.01%

Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few thoughts! Looks good overall! Excited for the significant speedup :)

pydantic/_internal/_std_types_schema.py Show resolved Hide resolved
pydantic/_internal/_std_types_schema.py Show resolved Hide resolved
@sydney-runkle sydney-runkle added the relnotes-performance Used for performance improvements. label Mar 21, 2024
@sydney-runkle
Copy link
Member

sydney-runkle commented Mar 21, 2024

The only failing fastapi test is due to a msg changing re an enum member error, and our version policy states that we can indeed expect msg changes in minor versions, so I think this is ok (https://docs.pydantic.dev/latest/version-policy/).

Perhaps we could just open a heads up with a test fix on the fastapi end? This is due to the fact that we removed the logic in the to_enum function which raised an error with a specific format for the allowed members...

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking solid! We've done a clear win for the JSON north star. The Python north start is less signficant than I hoped; I'll have to dig around with that another time and see if there's any possible wins...

pydantic/_internal/_std_types_schema.py Show resolved Hide resolved
@sydney-runkle
Copy link
Member

The only failing fastapi test is due to a msg changing re an enum member error, and our version policy states that we can indeed expect msg changes in minor versions, so I think this is ok (https://docs.pydantic.dev/latest/version-policy/).

Update, the issue is with the url being included now, which we can fix with a simple one liner PR where we add match_pydantic_error_url to the failing test. For now, we're skipping said failing test.

@sydney-runkle sydney-runkle marked this pull request as ready for review March 25, 2024 17:43
Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@sydney-runkle sydney-runkle enabled auto-merge (squash) March 25, 2024 17:51
@sydney-runkle sydney-runkle merged commit ac9e6ee into main Mar 25, 2024
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-performance Used for performance improvements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants