KEMBAR78
Move `enum` validation and serialization to Rust by samuelcolvin · Pull Request #9064 · pydantic/pydantic · GitHub
Skip to content

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
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-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.

@codspeed-hq
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
Contributor

@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 :)

@sydney-runkle sydney-runkle added the relnotes-performance Used for performance improvements. label Mar 21, 2024
@sydney-runkle
Copy link
Contributor

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...

@sydney-runkle
Copy link
Contributor

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
@samuelcolvin samuelcolvin force-pushed the rust-enum-validation branch from 0bf0172 to 1f0c7ae Compare March 25, 2024 17:44
Copy link
Contributor

@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!

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.

3 participants