Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize launch time #1

Open
alexdelorenzo opened this issue Dec 28, 2021 · 1 comment
Open

Optimize launch time #1

alexdelorenzo opened this issue Dec 28, 2021 · 1 comment

Comments

@alexdelorenzo
Copy link
Owner

alexdelorenzo commented Dec 28, 2021

Problem

Here's the issue:

$ time python -c "import sys, emoji, fire, more_itertools"
real    0m0.121s
user    0m0.105s
sys     0m0.019s

$ time python -c "import fire"
real    0m0.106s
user    0m0.086s
sys     0m0.023s

$ time python -m strs isalnum 1
real    0m0.146s
user    0m0.115s
sys     0m0.033s

Start up time, at minimum, will have a ~100ms duration on a NVMe drive with hot caches.

This doesn't really matter when using strs on the command line, but when you're writing scripts with a lot of string manipulation, it can be relatively slow:

$ time echo "$(str repeat 5 test | str join : | str split : | str nth 1 2 3 | str join ' ' | str col 1)"
test
real    0m0.234s
user    0m0.861s
sys     0m0.168s

Potential solutions

Using click can shave off ~34ms from start up:

$ time python3 -c "import click"
real    0m0.072s
user    0m0.059s
sys     0m0.016s

Nuitka, in general, can give a 4x execution speed up, which can result in a ~28ms to ~37ms start up time. Mypyc and Nuitka don't support Python 3.10, but Numba does and so does Cython. I have to look further into PyOxidizer and PyO3.

It would also help to profile it and see exactly what's going on during start up. I think the script might just be hitting the disk heavily with imports that are spread across many files. Dynamically loading dependencies might help in that case, or inlining.

Or, instead of relying on pipes to pass strings through different manipulation commands, strs can use Fire's command chaining feature, or click's command chaining feature. The CLI API might have to change, and the input handling might need to be refactored, in order for command chaining to work nicely with the current code and how it's structured.

That, or I can just port it to Rust.

@alexdelorenzo
Copy link
Owner Author

Nuitka has preliminary support for 3.10 in their development branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant