Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Dec 28, 2024

Also remove unnecessary schema copy.

Change Summary

Related issue number

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

Also remove unnecessary schema copy.
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Dec 28, 2024
Copy link

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: d285728
Status: ✅  Deploy successful!
Preview URL: https://d7bfb8e4.pydantic-docs.pages.dev
Branch Preview URL: https://ann-application-perf-test.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Dec 28, 2024

CodSpeed Performance Report

Merging #11186 will improve performances by 7.02%

Comparing ann-application-perf-test (d285728) with main (3294b9f)

Summary

⚡ 1 improvements
✅ 45 untouched benchmarks

Benchmarks breakdown

Benchmark main ann-application-perf-test Change
test_tagged_union_with_callable_discriminator_schema_generation 1.9 ms 1.8 ms +7.02%

Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _generate_schema.py
Project Total  

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

@@ -2106,7 +2106,7 @@ def _apply_single_annotation(self, schema: core_schema.CoreSchema, metadata: Any
return self.defs.definitions[new_ref]
schema['ref'] = new_ref # type: ignore

maybe_updated_schema = _known_annotated_metadata.apply_known_metadata(metadata, schema.copy())
maybe_updated_schema = _known_annotated_metadata.apply_known_metadata(metadata, schema)
Copy link
Member Author

Choose a reason for hiding this comment

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

apply_known_metadata already copies schema

Comment on lines +2143 to +2145
schema = get_inner_schema(source)
schema = self._apply_single_annotation(schema, annotation)
schema = self._apply_single_annotation_json_schema(schema, annotation)
Copy link
Member Author

Choose a reason for hiding this comment

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

This way, we don't go through _appy_single_annotation* for annotations with a custom __get_pydantic_core_schema__ as it is unnecessary.

@Viicos Viicos marked this pull request as ready for review December 29, 2024 15:42
@Viicos
Copy link
Member Author

Viicos commented Dec 29, 2024

This mostly improves performance for test_field_validators_serializers (which is ignored in codspeed), or for any similar use case where annotations with a custom __get_pydantic_core_schema__ method is used:

image

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.

Great find, thanks for making reviewing the perf diff easy!

@sydney-runkle sydney-runkle added relnotes-performance Used for performance improvements. and removed relnotes-fix Used for bugfixes. labels Dec 30, 2024
@sydney-runkle
Copy link
Contributor

Just as a side note, I think there's still a lot to do with #10036, I'm happy to take a deeper look at this for v2.11 :)

@sydney-runkle sydney-runkle merged commit 7b7db4f into main Dec 30, 2024
59 checks passed
@sydney-runkle sydney-runkle deleted the ann-application-perf-test branch December 30, 2024 15:38
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.

2 participants