Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Sep 2, 2024

Related issue:

A new copy argument is added to _WalkCoreSchema, defaulting to True. In the relevant steps of schema cleaning, no copy is performed.

Flamegraph:

Time order:

image

Left heavy:

image


The left heavy schema clearly shows that collect_refs (the first handler function to be used with walk_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):

  • Command: memray run -o k8s_v2_no_copy.bin k8s_v2.py && memray flamegraph k8s_v2_no_copy.bin

image

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Sep 2, 2024
@Viicos Viicos force-pushed the schema-cleaning-no-copy branch from f519d94 to 80e1de2 Compare September 2, 2024 16:04
Copy link

cloudflare-workers-and-pages bot commented Sep 2, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link

codspeed-hq bot commented Sep 2, 2024

CodSpeed Performance Report

Merging #10286 will not alter performance

Comparing schema-cleaning-no-copy (7967d58) with main (8fe7c8e)

Summary

✅ 38 untouched benchmarks

@Viicos Viicos force-pushed the schema-cleaning-no-copy branch from 80e1de2 to 9d4745c Compare September 2, 2024 16:10
Copy link
Contributor

github-actions bot commented Sep 4, 2024

Coverage report

Click to see where and how coverage changed

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

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

@sydney-runkle
Copy link
Contributor

@Viicos is this ready for review?

@sydney-runkle
Copy link
Contributor

@Viicos,

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.

@Viicos Viicos marked this pull request as ready for review September 27, 2024 13:50
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.

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!

@sydney-runkle sydney-runkle added relnotes-performance Used for performance improvements. and removed relnotes-fix Used for bugfixes. labels Sep 27, 2024
@sydney-runkle sydney-runkle merged commit 22ba7fa into main Sep 27, 2024
61 checks passed
@sydney-runkle sydney-runkle deleted the schema-cleaning-no-copy branch September 27, 2024 18:12
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