Schema cleaning: skip unnecessary copies during schema walking#10286
Merged
sydney-runkle merged 3 commits intomainfrom Sep 27, 2024
Merged
Schema cleaning: skip unnecessary copies during schema walking#10286sydney-runkle merged 3 commits intomainfrom
sydney-runkle merged 3 commits intomainfrom
Conversation
f519d94 to
80e1de2
Compare
Deploying pydantic-docs with
|
| Latest commit: |
7967d58
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aa61922c.pydantic-docs.pages.dev |
| Branch Preview URL: | https://schema-cleaning-no-copy.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10286 will not alter performanceComparing Summary
|
80e1de2 to
9d4745c
Compare
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||
Contributor
|
@Viicos is this ready for review? |
Contributor
|
Could you add a note to this PR re incompatibility with a cache based approach? I'm keen to accept this as is for now, then revert if we come up with a good caching solution pre our next release. |
sydney-runkle
approved these changes
Sep 27, 2024
Contributor
sydney-runkle
left a comment
There was a problem hiding this comment.
This looks good to me.
As mentioned on the schema walking performance analysis issue, I think there are more improvements to be made here, but this is a good start.
Thanks @Viicos!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue:
A new
copyargument is added to_WalkCoreSchema, defaulting toTrue. In the relevant steps of schema cleaning, no copy is performed.Flamegraph:
py-spy record -o k8s_v2_no_copy.json -f speedscope -- python k8s_v2.pyTime order:
Left heavy:
The left heavy schema clearly shows that
collect_refs(the first handler function to be used withwalk_core_schema) takes most of the time, and the other ones now represents almost nothing.Seems like ~1 second can be saved. Not bad, but not that great either. Perhaps dict copies aren't that expensive? Unsurprisingly, memory consumption is the same (~600MiB in the end):
memray run -o k8s_v2_no_copy.bin k8s_v2.py && memray flamegraph k8s_v2_no_copy.bin