flozz / rivalcfg

CLI tool and Python library to configure SteelSeries gaming mice
https://flozz.github.io/rivalcfg/
Do What The F*ck You Want To Public License
792 stars 65 forks source link

Improve CLI startup time #194

Closed gryzus24 closed 1 year ago

gryzus24 commented 1 year ago

Program startup time was really slow. After inspecting it with -Ximporttime it turned out to be pulling in a lot of unnecessary packages from pkg_resources responsible only for debug functionality.

Solution: reduce the scope of the debug import.

Note that this type of optimization is more of a hack than a solution, but considering it significantly improves startup time for the 99%+ of use cases it is worth implementing.

Before the patch:

$ time python3.10 -m rivalcfg --help > /dev/null

real    0m0,156s
user    0m0,125s
sys 0m0,023s

$ time python3.10 -m rivalcfg -s 800

real    0m0,260s
user    0m0,129s
sys 0m0,021s

After the patch:

$ time python3.10 -m rivalcfg --help > /dev/null

real    0m0,069s
user    0m0,050s
sys 0m0,011s

$ time python3.10 -m rivalcfg -s 800

real    0m0,185s
user    0m0,060s
sys 0m0,015s
flozz commented 1 year ago

Hello,

Thank you for the PR! Please fix the codding style (missing blank line after import) to allow me to merge :)

flozz commented 1 year ago

Thank you, this will be released with the next version :)