Skip to content

perf(cli): defer litellm import to cut cold start#147

Merged
0xKT merged 1 commit into
mainfrom
perf/defer_litellm_cli_coldstart
Jul 17, 2026
Merged

perf(cli): defer litellm import to cut cold start#147
0xKT merged 1 commit into
mainfrom
perf/defer_litellm_cli_coldstart

Conversation

@0xKT

@0xKT 0xKT commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Every raven command imported litellm eagerly, and litellm was ~85% of the
~2.35s cold start -- so even raven --version paid the full tax. This defers
litellm to the code paths that actually need a model:

  • Drop the top-level import litellm in the CLI entry module.
  • Make raven.agent and raven.providers PEP 562 lazy re-exports, so importing
    a submodule no longer eagerly constructs AgentLoop -> litellm (0 in-repo
    callers of the re-exports, so no behavior change).
  • Route every litellm import through a single import_litellm() helper that
    silences litellm's "Provider List" banner and suppresses its import-time DEBUG
    from the terminal (litellm installs its own stderr handler and logs while
    importing; the deferred import happens after raven's CLI logging setup, so the
    helper keeps that noise off the terminal / Ink TUI).

Result: raven --version starts in ~0.4s (from ~2.35s). Verified the everos
memory substrate was never on the startup path; it was not the bottleneck.

Type

  • Fix
  • Feature
  • Docs
  • CI / tooling
  • Refactor
  • Other

Verification

  • raven --version: ~2.35s -> ~0.4s (direct .venv/bin/raven).

  • python -X importtime -c "import raven.cli.commands": 0 litellm.

  • Real logging path (redirect_loguru_to_file + provider import) and an
    interactive raven tui: 0 LiteLLM:DEBUG lines leaked to the terminal.

  • make test-python (now includes test_cli_smoke.py + test_litellm_setup.py).

  • Affected suites (agent loop / providers / token_wise / tui logging isolation): pass.

  • Relevant tests pass locally

  • Relevant lint / type checks pass locally

  • User-facing docs or screenshots are updated when needed

Risk

  • Security impact considered
  • Backward compatibility considered
  • Rollback path is clear for risky changes

Related Issues

Fixes #142

Every raven command imported litellm eagerly (via the CLI entry module and
the deep_research_commands -> raven.agent chain), and litellm is ~85% of the
~2.35s cold start. Defer it: make raven.agent and raven.providers PEP 562
lazy re-exports, drop the eager import in the CLI entry, and route every
litellm import through a shared helper that silences its terminal noise.
raven --version now starts in ~0.4s.

Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
@0xKT
0xKT requested a review from arelchan July 17, 2026 08:16
@0xKT
0xKT merged commit 839bf84 into main Jul 17, 2026
8 checks passed
@0xKT
0xKT deleted the perf/defer_litellm_cli_coldstart branch July 17, 2026 08:19
@cyfyifanchen cyfyifanchen mentioned this pull request Jul 19, 2026
12 tasks
cyfyifanchen added a commit that referenced this pull request Jul 19, 2026
## Summary

Bump Raven package metadata from 0.1.5 to 0.1.6 so the release tag can
build a wheel from the current main branch.

This release carries the changes merged after v0.1.5:

- Version display now derives from installed package metadata (#139).
- Tracing dashboard port reuse avoids taking over non-Raven viewers
(#141).
- CLI startup defers LiteLLM imports for faster cold start (#147).
- Self-evolution stack and AppWorld benchmark entry points are included
(#140).
- TUI render delay is reduced by deferring provider and memory loading
(#157).

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [x] Other

## Verification

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

Commands run:

- `PYTHONPATH=. uv run pytest
tests/test_cli_smoke.py::test_version_flag_matches_installed_metadata
-q`
- `make check-commits COMMIT_RANGE=origin/main..HEAD`
- `PYTHONPATH=. uv run python scripts/check_commit_file.py
/tmp/raven-commit-msg.txt`

No user-facing docs or screenshots were needed for this version metadata
bump; release notes will be published with the GitHub Release.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

This changes package metadata only. Rollback is to delete the v0.1.6
tag/release if publication fails before users upgrade, or publish a
follow-up patch release if a released package issue is found.

## Related Issues

N/A
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.

perf(cli): eager litellm import dominates CLI cold-start

2 participants