Skip to content

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
@parthea parthea enabled auto-merge (squash) June 4, 2024 11:46
@parthea parthea merged commit ac098a7 into main Jun 4, 2024
@parthea parthea deleted the move_async_warning branch June 4, 2024 11:47
parthea added a commit that referenced this pull request Jun 5, 2024
parthea added a commit that referenced this pull request Jun 5, 2024
@parthea parthea restored the move_async_warning branch June 5, 2024 16:16
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

3 participants