Skip to content

optimize CheckedSession.__setattr__ or ._check_key_value #1171

@gdementen

Description

@gdementen

It is currently much more expensive than necessary (it recomputes annotations and TypeAdapter on each attribute set, whether that particular attribute has already been set or not). This is not super important though given that we use it to store arrays which themselves take much more time to compute than the attribute setter. Still, in some rare workflows, I think this could make a difference. Edit: Note that even nested loops setting one element of an array at a time should not be impacted because those are using __setitem__ on the arrays themselves, not __setattr__ or __setitem__ on the session, so this would be even rarer than I initially thought.

It should be possible to cache setters (like Pydantic itself does BTW). I have actually tried doing so (yet another instance of a "how hard could it be?" 😉) and it mostly works... except inheritance 😢.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions