Skip to content

Allow non-scalar values as tagged union keys #655

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

Merged
merged 1 commit into from
Jun 8, 2023
Merged

Conversation

adriangb
Copy link
Member

@adriangb adriangb commented May 31, 2023

See also pydantic/pydantic#5958

Selected Reviewer: @samuelcolvin

@codspeed-hq
Copy link

codspeed-hq bot commented May 31, 2023

CodSpeed Performance Report

Merging #655 tagged-union-enum (83c2ceb) will not alter performances.

Summary

🔥 4 improvements
❌ 0 regressions
✅ 121 untouched benchmarks

🆕 0 new benchmarks
⁉️ 0 dropped benchmarks

Benchmarks breakdown

Benchmark main tagged-union-enum Change
🔥 test_validate_literal[json-few_small_strings] 26.8 µs 20.7 µs 22.81%
🔥 test_validate_literal[json-few_large_strings] 28.2 µs 22 µs 22.14%
🔥 test_validate_literal[json-many_small_strings] 43.1 µs 20.9 µs 51.40%
🔥 test_validate_literal[json-many_large_strings] 28.7 µs 22.2 µs 22.87%

@adriangb
Copy link
Member Author

please review

@codecov-commenter
Copy link

codecov-commenter commented May 31, 2023

Codecov Report

Merging #655 (83c2ceb) into main (d2f4226) will decrease coverage by 0.16%.
The diff coverage is 89.90%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #655      +/-   ##
==========================================
- Coverage   93.90%   93.74%   -0.16%     
==========================================
  Files          99       99              
  Lines       13756    13726      -30     
  Branches       25       25              
==========================================
- Hits        12917    12868      -49     
- Misses        833      852      +19     
  Partials        6        6              
Impacted Files Coverage Δ
src/lookup_key.rs 92.38% <ø> (ø)
src/validators/union.rs 81.48% <64.51%> (-5.67%) ⬇️
pydantic_core/core_schema.py 96.88% <100.00%> (ø)
src/input/input_abstract.rs 86.11% <100.00%> (+0.81%) ⬆️
src/input/input_python.rs 98.06% <100.00%> (-0.26%) ⬇️
src/validators/literal.rs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2f4226...83c2ceb. Read the comment docs.

@dmontagu
Copy link
Collaborator

dmontagu commented Jun 1, 2023

Does this solve the enum discriminator thing on the pydantic side? Also, are there any (non-benchmarked?) (negative) performance implications? Not that that would make me reject it but I think it's worth understanding.

@adriangb
Copy link
Member Author

adriangb commented Jun 1, 2023

Does this solve the enum discriminator thing on the pydantic side?
It does, although I had forgotten to remove the xfail. It doesn't allow validating scalar values against a non-scalar Enum even if it has scalar values (see pydantic/pydantic@cc6577d#diff-3e4f2ce6ba438060e163151503e9bb6cea70760b0465f1a6e17a8646826a9b7d).

Also, are there any (non-benchmarked?) (negative) performance implications? Not that that would make me reject it but I think it's worth understanding.

It doesn't seem like we have any benchmarks. I can add some to main and rebase this PR.

@adriangb adriangb force-pushed the tagged-union-enum branch from fda02f2 to 093f6c5 Compare June 1, 2023 14:10
@adriangb
Copy link
Member Author

adriangb commented Jun 1, 2023

Okay so small performance regression for JSON, probably because we now convert to Python just to match. We could do the same thing we do with literal validator where we try to match a Rust string/int before using a Python dict. The downside of that (aside from adding complexity) is that the match order is no longer preserved w.r.t. the input schema.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

Without looking through this in line-by-line detail, this looks good to me.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

In general I think this looks great.

I want to be a bit more sure that the performance regressions are an artefact of codspeed, not real - maybe we could create another trivial PR and see if we get the same thing?

@art049 is there any chance this big change in benchmarks is a result of issues with Codspeed?

@samuelcolvin
Copy link
Member

please update.

@art049
Copy link
Contributor

art049 commented Jun 5, 2023

@samuelcolvin @adriangb I'm having a look to understand if it is noise or not since apparently it also happened in #656 . I'll keep you updated.

Edit: let's follow up on #656 since it's easier to understand the behavior there.

@adriangb adriangb force-pushed the tagged-union-enum branch from fe90d7a to cca08c4 Compare June 7, 2023 18:40
@adriangb
Copy link
Member Author

adriangb commented Jun 7, 2023

please review

@adriangb adriangb force-pushed the tagged-union-enum branch from 9075107 to 83c2ceb Compare June 8, 2023 22:39
@adriangb
Copy link
Member Author

adriangb commented Jun 8, 2023

There we go now this has no performance degradations and actually makes some things 50% faster @samuelcolvin

@adriangb
Copy link
Member Author

adriangb commented Jun 8, 2023

Since I think all of the feedback (including performance regressions) has been addressed I'm going to go ahead and merge this

@adriangb adriangb merged commit 3b1a6a7 into main Jun 8, 2023
@adriangb adriangb deleted the tagged-union-enum branch June 8, 2023 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants