Skip to content

perf(cli): defer fastapi/uvicorn imports in cloud module#20440

Draft
zzstoatzz wants to merge 2 commits intomainfrom
defer-cloud-imports
Draft

perf(cli): defer fastapi/uvicorn imports in cloud module#20440
zzstoatzz wants to merge 2 commits intomainfrom
defer-cloud-imports

Conversation

@zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Jan 28, 2026

Summary

  • Move fastapi and uvicorn imports inside functions that actually use them, rather than importing at module load time
  • This defers the import cost until browser-based login is actually used (which is rare for most CLI invocations)

Benchmark Results

Benchmarked in isolated CI environment (workflow run):

Command Delta p-value Significant?
prefect --help -4% <0.001 Yes
prefect --version -2% <0.001 Yes
prefect version -1% 0.33 No

No regressions. Small but statistically significant improvements on startup commands.

Test plan

  • Existing tests pass (no functional change, just import timing)
  • Benchmark comparison in isolated CI shows no regressions

🤖 Generated with Claude Code

Move fastapi and uvicorn imports inside functions that actually use them,
rather than importing at module load time. This saves ~65ms on CLI startup
for commands that don't use browser-based login (which is most commands).

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zzstoatzz zzstoatzz added the performance Related to an optimization or performance improvement label Jan 28, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 28, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing defer-cloud-imports (6492f2e) with main (fd33142)

Summary

✅ 2 untouched benchmarks

Configuration file for python-cli-bench to measure CLI startup performance.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

This pull request is stale because it has been open 14 days with no activity. To keep this pull request open remove stale label or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Related to an optimization or performance improvement status:stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments