Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize access to filter map in find_annotated_strategy #3981

Closed
wants to merge 1 commit into from

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented May 10, 2024

Fixes #3980.

I'm wondering if it makes sense to use functools.cache on get_constraints_filter_map as well?

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it makes sense to use functools.cache on get_constraints_filter_map as well?

It's important to avoid caching the empty-map result, in case the module is imported later, and then cheap enough that it's not worth a fancy only-cache-one-branch system.

@@ -341,10 +341,11 @@ def find_annotated_strategy(annotated_type):
return arg

filter_conditions = []
filter_map = get_constraints_filter_map()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move this inside the if "annotated_types" in sys.modules: below, to save a bit of time in the no-annotated-types case.

@Zac-HD Zac-HD closed this in #3986 May 13, 2024
@Viicos Viicos deleted the issue/3980 branch May 13, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Small optimization in find_annotated_strategy
2 participants