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

fix performance regression for JSON tagged union #1552

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

davidhewitt
Copy link
Contributor

Change Summary

Fixes unintentional performance loss from #1538

At the same time I thought I would compress this down a bit further.

Related issue number

N/A

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@@ -117,44 +117,6 @@ fn union_serialize<S>(
Ok(None)
}

fn tagged_union_serialize<S>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved down, to be a method on TaggedUnionSerializer.

// If extra.check is SerCheck::None, we're in a top-level union. We should thus raise
// this warning
let value_str = truncate_safe_repr(value, None);
extra.warnings.custom_warning(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this warning here from get_discriminator_value, seemed more correct as the other warnings are raised in union_serialize.

mut selector: impl FnMut(&CombinedSerializer, &Extra) -> PyResult<S>,
extra: &Extra,
) -> PyResult<Option<S>> {
if let Some(tag) = self.get_discriminator_value(value) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sure that we always try to get the tag by having the method call here 😉

Copy link

codspeed-hq bot commented Nov 21, 2024

CodSpeed Performance Report

Merging #1552 will not alter performance

Comparing dh/fix-tagged-union-regression (a38aacd) with main (4477692)

Summary

✅ 155 untouched benchmarks

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.

Nice work, thanks for consolidating!

@sydney-runkle sydney-runkle merged commit e4de8a6 into main Nov 21, 2024
29 checks passed
@sydney-runkle sydney-runkle deleted the dh/fix-tagged-union-regression branch November 21, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants