perf(app): lazy-load subcommand modules to halve binary startup#17
Merged
Conversation
LazyTyperGroup keeps `rc0.commands.*` out of the import graph until a user actually runs a subcommand. Top-level help and version no longer pay for httpx, pydantic models, or rich import overhead. Measured on Apple Silicon (warm cold-start, median of 7 runs): - `rc0 --version`: ~270ms -> ~115ms - `rc0 --help`: ~310ms -> ~155ms `tests/perf/test_startup.py` (gated by `RC0_PERF=1` plus a built binary) asserts both stay under 200ms so future regressions fail CI. `packaging/pyinstaller-hooks/hook-rc0.py` runs `collect_submodules` over `rc0.commands` so PyInstaller (which can't see `importlib.import_module` strings) still bundles every subcommand. The CI release workflow and the local `rc0.spec` both point at this hooks dir. `introspect` walks via `list_commands`/`get_command` so the JSON schema still enumerates lazily-registered subcommands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rc0.commands.*are now imported on demand by a newLazyTyperGroupinsrc/rc0/app.py.rc0 --helpandrc0 --versionno longer pull in httpx, pydantic models, or the rich help formatter.packaging/pyinstaller-hooks/hook-rc0.py(usescollect_submodules), wired into both the localrc0.specand the GitHub release workflow.tests/perf/test_startup.py(gated byRC0_PERF=1+ a built binary) enforces a 200ms median budget so future regressions fail CI.Measured on Apple Silicon (warm, median of 7 runs)
rc0 --version: ~270ms → ~115msrc0 --help: ~310ms → ~155msTest plan
uv run ruff check . && uv run ruff format --check . && uv run mypy && uv run pytest— all green (459 passed, perf gated-skipped, coverage 90.48%)RC0_PERF=1 pytest tests/perf/test_startup.pyagainst the built binary — both assertions pass--helpagainst the binary (70/70 succeed; 2 pre-existingdnssec simulatecases identical in source vs. binary)RC0=dist/rc0/rc0 SKIP_MUTATIONS=1 scripts/smoke-live.sh— 72 / 72 valid assertions pass (1 stale assertion in the smoke script around hoisted-flag ordering is pre-existing and unrelated; tracked as a follow-up)