pydantic-core icon indicating copy to clipboard operation
pydantic-core copied to clipboard

Optimized traversal of schema tree for schema cleaning (`GenerateSchema.clean_schema`)

Open MarkusSintonen opened this issue 4 months ago • 3 comments

Change Summary

Adds schema tree traversal which gathers necessary schema nodes and information for schema inlining and discriminator handling. Schema tree traversal is done in a single pass gathering the needed information. This is used in GenerateSchema.clean_schema handling. Required for PR https://github.com/pydantic/pydantic/pull/10655 This makes schema cleaning much more efficient where the biggest bottleneck has been the Python side tree traversal. This especially with lots of models or deep models.

Related issue number

See above Pydantic side PR.

Checklist

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

Selected Reviewer: @sydney-runkle

MarkusSintonen avatar Oct 18 '24 10:10 MarkusSintonen