Improve Client CLI startup performance with lazy imports
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## Background
Client CLI (`backend.ai` command) startup speed is slow due to eager imports of heavy dependencies at module level. This affects developer experience and CI/CD pipeline performance.
Agent and Storage Proxy already have lazy import enforcement tests (see `tests/unit/cli/test_lazy_import_agent.py`, `test_lazy_import_storage_proxy.py`) that ensure CLI commands use lazy imports to reduce startup time.
**Related issues:** lablup/backend.ai#663, lablup/backend.ai#5327
## Current Status
### Components with lazy import tests
- ✅ Agent CLI (`ai.backend.agent.cli`)
- ✅ Storage Proxy CLI (`ai.backend.storage.cli`)
- ⚠️ Manager CLI (`ai.backend.manager.cli`) - test exists but is commented out
### Components missing lazy import tests
- ❌ \***Client CLI**\* (`ai.backend.client.cli`) - large module with ~50 command files
## Goals
1. Add lazy import enforcement test for Client CLI
2. Refactor Client CLI imports to use lazy loading (imports inside functions)
3. Review and potentially re-enable Manager CLI lazy import test
## Tasks
### 1. Add test for Client CLI
- Create `tests/unit/cli/test_lazy_import_client.py`
- Follow the pattern from agent/storage tests
- Identify heavy modules that should not be loaded at CLI startup (e.g., session logic, API models, pandas/numpy dependencies)
### 2. Refactor Client CLI imports
- Move heavy imports inside command functions
- Ensure CLI help text remains fast
- Verify startup time improvement
### 3. Review Manager CLI test
- Investigate why `test_lazy_import_manager.py` is commented out
- Fix any issues and re-enable if possible
## Success Criteria
- Client CLI startup time reduced significantly
- All lazy import tests passing
- No regression in CLI functionality
JIRA Issue: BA-4920
Contributor guide
Assessment
This issue has not been assessed yet.