TaskObserver: don't inspect on_push_frame signature for every frame

This commit is contained in:
Aleix Conchillo Flaqué
2025-08-02 20:39:59 -07:00
parent 061f2086b2
commit d6d39fc873
2 changed files with 20 additions and 14 deletions

View File

@@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue with the `TavusVideoService` where an error was thrown due to - Fixed an issue with the `TavusVideoService` where an error was thrown due to
missing transcription callbacks. missing transcription callbacks.
### Performance
- Fixed an issue in `TaskObserver` (a proxy to all observers) that was degrading
global performance.
## [0.0.77] - 2025-07-31 ## [0.0.77] - 2025-07-31
### Added ### Added

View File

@@ -153,13 +153,9 @@ class TaskObserver(BaseObserver):
async def _proxy_task_handler(self, queue: asyncio.Queue, observer: BaseObserver): async def _proxy_task_handler(self, queue: asyncio.Queue, observer: BaseObserver):
"""Handle frame processing for a single observer.""" """Handle frame processing for a single observer."""
warning_reported = False on_push_frame_deprecated = False
while True:
data = await queue.get()
signature = inspect.signature(observer.on_push_frame) signature = inspect.signature(observer.on_push_frame)
if len(signature.parameters) > 1: if len(signature.parameters) > 1:
if not warning_reported:
import warnings import warnings
with warnings.catch_warnings(): with warnings.catch_warnings():
@@ -168,7 +164,12 @@ class TaskObserver(BaseObserver):
"Observer `on_push_frame(source, destination, frame, direction, timestamp)` is deprecated, us `on_push_frame(data: FramePushed)` instead.", "Observer `on_push_frame(source, destination, frame, direction, timestamp)` is deprecated, us `on_push_frame(data: FramePushed)` instead.",
DeprecationWarning, DeprecationWarning,
) )
warning_reported = True
on_push_frame_deprecated = True
while True:
data = await queue.get()
if on_push_frame_deprecated:
await observer.on_push_frame( await observer.on_push_frame(
data.src, data.dst, data.frame, data.direction, data.timestamp data.src, data.dst, data.frame, data.direction, data.timestamp
) )