Performance: Add static TypeAdapters and reuse them. #15047
Labels
enhancement
An improvement of an existing feature
performance
Related to an optimization or performance improvement
Describe the current behavior
Today Prefect liberally uses Pydantic's TypeAdapter to validate models of type
Generic[BaseModel]
, e.g.Morally, TypeAdapter under the hood is a lower-level
create_model
which has a non-trivial cost to create.This means today Prefect is paying that overhead in almost every client call that fetches a list.
Describe the proposed behavior
For each relevant Prefect BaseModel, e.g.
Variable
create aalongside that BaseModel for reuse. Note with our switch to
defer_build
, we need to explicitly turn ondefer_build
for each TypeAdapter so that we don't force the creation of a serializer accidentally.https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.experimental_defer_build_mode
Example Use
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: