Avoid top-level imports in `cli.py`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 12.5k
- Forks
- 998
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 10
Description
Outputing the help takes about one second on my system:
$ time llm --help > /dev/null
llm --help > /dev/null 0.82s user 0.10s system 99% cpu 0.920 total
That's because cli.py is importing a lot of libraries at the top-level. I propose moving the imports in that file to the functions where they are needed. It may not look asthetic, but it will speed up the call to --help by many orders of magnitudes, and probably somewhat speed up the warm up time when calling subcommands.
Let me know if I can help out with a PR. (It's probably also something that an LLM would be good at.)
Edit: I'm seeing that __init__.py is also affected, and my suggestions probably doesn't apply there ...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading cli.py and measuring the existing llm --help timing shown in the issue. Move imports that are only needed by specific functions into those functions, while checking the note about init.py separately. Done means help loads substantially faster without changing command behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100