I have been working on some perf issues in some code (that, granted, has many problems intrinsic to its design).
I’ve found that async_to_sync
and sync_to_async
-wrapped calls tend to cost me 3ms-5ms per call. This is obviously super dependent on use cases, but I’m glad to have an idea of the number now. (This number doesn’t include the initial wrap, in general I have been declaring a wrapped function then calling that).
Obviously for a single call it doesn’t matter, but in our case we have calls in pretty hot loops, and it is a bit painful.
and of course something like:
await sync_to_async(getattr)(instance, 'field_name')
to get the field name is a good way to cause pain.