From fe6e5e7b0dd011b29f32fba11753f7f428a47dac Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 19:30:56 +0000 Subject: [PATCH] perf: Wrap gzip/json export dump in asyncio.to_thread Offload blocking I/O (gzip writing and json serialization) in `DataExportBackup.execute_backup` to a background thread to avoid stalling the main event loop. Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com> --- archive/v1/src/tasks/backup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archive/v1/src/tasks/backup.py b/archive/v1/src/tasks/backup.py index ff48d0e896..45b0266339 100644 --- a/archive/v1/src/tasks/backup.py +++ b/archive/v1/src/tasks/backup.py @@ -320,8 +320,11 @@ async def execute_backup(self, session: AsyncSession) -> Dict[str, Any]: export_data["tables"]["pose_detections_recent"] = pose_data # Write compressed JSON - with gzip.open(backup_path, 'wt', encoding='utf-8') as f: - json.dump(export_data, f, indent=2, default=str) + def _write_json_sync(): + with gzip.open(backup_path, 'wt', encoding='utf-8') as f: + json.dump(export_data, f, indent=2, default=str) + + await asyncio.to_thread(_write_json_sync) backup_size_mb = self._get_file_size_mb(backup_path)