Commit 540ec85
perf(tests): cut subprocess worker startup ~55% via lazy imports
Test workers used to spend ~310ms per spawn on import overhead, dominated
by two avoidable costs:
1. Workers imported `tests.test_rpc` to get `RpcFixtureService` /
`RpcFixtureServiceImpl`, dragging in pytest, conftest, and httpx —
none of which the worker uses at runtime. Extract the fixture service
(Protocol, Impl, state classes, _CancelProbe, DescribeResult,
StreamHeader, Color) into a new `tests/_fixture_service.py`. The
seven `serve_fixture_*.py` workers import from there directly;
`tests.test_rpc` re-exports the names so existing test imports keep
working.
2. `vgi_rpc/__init__.py` eagerly imported `vgi_rpc.http` (Falcon, httpx),
`vgi_rpc.sentry` (sentry_sdk), `vgi_rpc.otel`, `vgi_rpc.s3`, and
`vgi_rpc.gcs` even though most callers — and every pipe/subprocess
worker — never use them. Convert to module-level `__getattr__` lazy
loading keyed by `_LAZY_ATTRS`. `__all__` is built once at import
time by probing the *leaf* third-party deps via
`importlib.util.find_spec` (probing `vgi_rpc.http._oauth_jwt` would
import `vgi_rpc.http` and defeat the lazy point).
Results on this machine:
- Worker cold start: 312ms → 140ms (-55%)
- `import vgi_rpc`: ~250ms → ~115ms (-54%)
- Full pytest suite: 132s → 94s (-29%)
Public surface unchanged: `from vgi_rpc import http_connect`,
`vgi_rpc.SentryConfig`, `from vgi_rpc import *` all behave identically.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cc3e24e commit 540ec85
10 files changed
Lines changed: 648 additions & 544 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments