Replies: 3 comments
-
Most of typer's startup time (>85%) comes from loading rich modules in
This means that these time-consuming import are not needed "normal" execution flows (no help, no errors). If you're not using rich in your CLI, you can avoid this delay by using My app is using rich, but I would still want to avoid that delay, mainly because of autocompletion. The 400 ms delay after pressing the tab key is quite noticeable. In my own code, I can defer loading rich (and other slow dependencies) until it's actually needed, so that it doesn't slow down autocompletion. However, I cannot avoid the import of Would you be interested in a PR that changes |
Beta Was this translation helpful? Give feedback.
-
I'd second this - I also ran into the same thing, where I'd a simple cli app that had annoying latency in the startup time: using Deferring the import unless its actually needed seems like it'd be a good idea (or failing that, some way to flag that I don't want it to be used even if installed) |
Beta Was this translation helpful? Give feedback.
-
Different library, but this is something we noticed in More info: https://ewels.github.io/rich-click/blog/2024/04/30/version-1.8/ |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
Is there any way to increase performance of using Typer? For example, I could imagine there are some flags one can disable?
I'm running Typer on a Raspberry Pi 3, which is - of course - not as fast as my MacBook.
Stats
$ time python test.py hello real 0m2.071s user 0m1.936s sys 0m0.112s
For my own, larger but not excessive, CLI
$ time python cli.py --help real 0m5.411s user 0m4.656s sys 0m0.301s
I saw in other issues I could perhaps make my imports dynamic to shave off some time, but perhaps there are some Typer-related features I can leverage.
Operating System
Linux
Operating System Details
Raspberry Pi 3
Typer Version
0.9.0
Python Version
3.9.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions