perf: lazy imports and session reuse for 93% faster CLI startup#67
perf: lazy imports and session reuse for 93% faster CLI startup#67
Conversation
|
@copilot how can i test your changes and see the perf improvment? |
You can measure the improvement with Python's 1. Quick before/after import time: # On the main branch (before):
git stash && git checkout main
python -c "import time; s=time.perf_counter(); import fabric_cli.main; print(f'{(time.perf_counter()-s)*1000:.0f}ms')"
# On this branch (after):
git checkout copilot/improve-cli-latency-performance
python -c "import time; s=time.perf_counter(); import fabric_cli.main; print(f'{(time.perf_counter()-s)*1000:.0f}ms')"2. Detailed import profiling: python -X importtime -c "import fabric_cli.main" 2>&1 | sort -t'|' -k2 -rn | head -20This shows cumulative import times per module — you'll see 3. End-to-end CLI timing: time fab --version
time fab --help4. Run the automated perf tests included in this PR: python -m pytest tests/test_utils/test_lazy_load.py -vThis runs 8 tests including On the CI environment I measured ~737ms → ~54ms for the module import (93% reduction). |
|
@copilot the fab:build type check code failed. fixed it |
- Lazy command loading via lazy_command() utility — defers command module imports until invoked - Deferred auth & interactive imports in main.py (auth ~160ms, prompt_toolkit ~64ms) - Deferred psutil in fab_context.py with TYPE_CHECKING guard - Config write optimization — init_defaults() skips write when unchanged - HTTP session reuse with retry adapter for connection pooling - Extracted fab_describe_commands.py from parser registration - 8 new tests covering lazy loading, startup, session reuse, config optimization Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
14c1945 to
715bedc
Compare
Co-authored-by: ayeshurun <98805507+ayeshurun@users.noreply.github.com>
scripts/benchmark_startup.py— a self-contained script to compare CLI startup performance between branches✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.