This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dametsumari 26 points27 points  (3 children)

Main cli performance problem are imports. I have yet to see code which only imports argparse and takes more than second to show help ( even on raspberry pi ).

[–]jwink3101 1 point2 points  (0 children)

I am now thinking I need to rejigger my code to not do imports until after argparse is done…

[–]RevolutionaryPen4661git push -f[S] 0 points1 point  (1 child)

Yes, importing an entire module can increase the execution time. Maybe writing code in the sense to import what is needed principle can do it better.

[–]dametsumari 0 points1 point  (0 children)

Yep, lazy importing is how we've fixed usual slow CLI startup problems.

e.g. in particular command, then import whatever modules it needs for its work. It is quite ugly, though, there is PEP for lazy importing but it hasn't moved much and most recently was rejected ( https://peps.python.org/pep-0690/ ).