reduce baseline memory ~50-70MB by deferring heavy imports (#1241)
* reduce baseline memory ~50-70MB by deferring heavy imports
- move psycopg[binary] from production to dev deps (only needed for
alembic migrations, app uses asyncpg via greenlet bridge)
- defer r2.py import in storage/__init__.py (boto3/botocore loaded
on first storage access, not at startup)
- defer aioboto3 + heavy deps in export_tasks.py into process_export()
(background task that runs rarely, was pulling in full boto3 stack
at startup via api/exports.py import chain)
- defer export_tasks import in tasks/__init__.py (matching existing
jetstream deferral pattern)
production machine: 1GB RAM, 440MB RSS at idle. these changes remove
~50-70MB of imports that were loaded at startup but only needed during
uploads/exports.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix beartype NameError: use string annotations for deferred type
beartype_this_package() evaluates annotations at import time, so
`from __future__ import annotations` doesn't help. use string
literal annotations instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix beartype forward ref: use Any annotation for deferred storage
beartype_this_package() resolves forward references on module-level
variables at import time, even with string annotations. use Any to
avoid the forward ref while keeping ty happy.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix test patch targets for deferred imports in export_tasks
Since aioboto3, aiofiles, db_session, and storage are now imported
inside process_export() rather than at module level, patches must
target the source modules directly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
authored by