Skip to content

fix: lazy load dspy for faster CLI help#37

Merged
isaacbmiller merged 1 commit intocmpnd-ai:mainfrom
MaximeRivest:fix/lazy-load-dspy-for-faster-help
Jan 16, 2026
Merged

fix: lazy load dspy for faster CLI help#37
isaacbmiller merged 1 commit intocmpnd-ai:mainfrom
MaximeRivest:fix/lazy-load-dspy-for-faster-help

Conversation

@MaximeRivest
Copy link
Copy Markdown
Contributor

Summary

  • Move dspy_cli.server.runner import from module level to inside the serve() function
  • This avoids loading dspy (~6s) when running dspy-cli --help

Performance

Time
Before 5.79s
After 0.10s

~56x faster help output.

Changes

  • 1 file changed, 2 insertions, 1 deletion
  • Standard lazy import pattern (same approach used by Django, FastAPI, Click)

Test plan

  • Verified dspy-cli --help no longer imports dspy
  • Verified dspy-cli serve still works (imports dspy when needed)

🤖 Generated with Claude Code

Move the dspy_cli.server.runner import from module level to inside
the serve() function. This avoids loading dspy (~6s) when running
`dspy-cli --help`.

Before: 5.79s
After:  0.10s

Also update test to patch at source module instead of local name.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@MaximeRivest MaximeRivest force-pushed the fix/lazy-load-dspy-for-faster-help branch from 3120a1e to 6ea3232 Compare January 15, 2026 23:55
@isaacbmiller isaacbmiller merged commit 2b59513 into cmpnd-ai:main Jan 16, 2026
1 check passed
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.

2 participants