Skip to content

perf(cli): lazy-load server, pathspec, and protocol imports#164

Merged
georgeh0 merged 1 commit into
mainfrom
g/perf-lazy-cli-imports
May 8, 2026
Merged

perf(cli): lazy-load server, pathspec, and protocol imports#164
georgeh0 merged 1 commit into
mainfrom
g/perf-lazy-cli-imports

Conversation

@georgeh0
Copy link
Copy Markdown
Member

@georgeh0 georgeh0 commented May 8, 2026

Summary

  • Cuts ccc <subcommand> cold-cache startup from ~0.5–0.9s to ~0.15s by lazy-loading expensive imports off the CLI hot path.
  • cocoindex_code/__init__.py no longer eagerly imports .server (which dragged in mcp.server.fastmcp ~300ms); a PEP 562 __getattr__ keeps the cocoindex-code = "cocoindex_code:main" console script working.
  • settings.py defers pathspec into load_gitignore_spec(), and cli.py moves protocol type-only imports under TYPE_CHECKING plus lazy-loads DaemonStartError/DoctorCheckResult at use sites.
  • Drops a stale paragraph from CLAUDE.md.

Test plan

  • uv run mypy . — clean
  • uv run pytest tests/ — 193 passed
  • Manual smoke: ccc status, ccc --help

Cuts `ccc status` cold-cache startup from ~0.5-0.9s to ~0.15s.

- `cocoindex_code/__init__.py`: replace eager `from .server import main`
  with a PEP 562 `__getattr__` so importing the package no longer pulls
  `mcp.server.fastmcp` (~300ms). The `cocoindex-code = "cocoindex_code:main"`
  console script still resolves.
- `settings.py`: defer `from pathspec import GitIgnoreSpec` into
  `load_gitignore_spec()` (only called by indexer/daemon).
- `cli.py`: move protocol type-only imports under `TYPE_CHECKING`
  (safe with `from __future__ import annotations`); lazy-import
  `DaemonStartError` inside the wrapper and `DoctorCheckResult` next to
  the existing lazy `client` import.

Also drops a stale paragraph from CLAUDE.md.
@georgeh0 georgeh0 merged commit d429632 into main May 8, 2026
4 checks passed
@georgeh0 georgeh0 deleted the g/perf-lazy-cli-imports branch May 8, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant