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

chore: move retry async check to wrap time #649

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

daniel-sanche
Copy link
Contributor

We recently made a change to the synchronous version of the Retry class to inspect each output, and raise a warning if the sync Retry class was accidentally used with an async function

This is a useful check, but the implementation adds significant overhead, almost doubling the processing time in a quick benchmark I ran (0.94s -> 1.84s)

This PR moves the check to happen once at wrap time, instead of on each retry attempt. This should give us most of the benefits, without the ongoing performance hit

Note that this implementaiton isn't quite as thouogh as the previous one: iscouroutinefunction won't catch standard functions that happen to return an awaitable, like the previous implementation would. But I think this trade-off is worth it for the performance gain

Fixes #542

@daniel-sanche daniel-sanche requested review from a team as code owners May 3, 2024 19:51
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise a warning in google.api_core.retry.retry_target if the return value is awaitable
2 participants