-
Notifications
You must be signed in to change notification settings - Fork 128
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
Improve startup time #472
Comments
@willingc I'll dig into this. |
Just curious, are you seeing it being slow on Linux too? |
I guess the question is how slow is "slow"? Running my processor at 2.4Ghz, it takes 1.073s to run If my laptop processor is running with dynamic frequency scaling, the EDIT: This is with Python 3.7, btw. |
I notice that Ideally, all this code should live |
The specific start case that I was seeing was typing |
@willingc can you post the output of |
Hi @groutr, Whelp in true software fashion it's not slow today. lol Here's the output requested: If you want feel free to close now. |
As another data point, on macOS 2.4 GHz Intel Core i5: |
Thanks @willingc and @jasongrout. I'm going to experiment with restructuring the cli to import things lazily. |
Looks like the help pages are probably the worst case scenario. However, I would argue that if the help pages aren't fast, it gives the impression that the program itself is slow. Fortunately, the help pages are easy to speed up. I was able to drop the time from >1s to about < .1s on my machine. |
Example
|
I can confirm that the issue still exists. Using augur for the first time today and I was surprised at how unresponsive the CLI is. Very unusual for and potentially off-putting. Really shouldn't be hard to fix for the common case of displaying help information. Here's another data point
with the following machine
|
Noting that this is impacting CI run times. Example: the latest scheduled run took 13m43s to complete. The bottleneck is cram tests which take ~11 minutes to run. Some cram tests do take a while, but I suspect a chunk of it is simply startup time. |
Cram tests are so slow. It's particularly painful to iterate on them in local dev. |
I found this lazy ArgumentParser approach that seemed promising at a quick glance and tried it out: 31d8df3 It needs a lot more work as detailed in the commit message, but seems like a potential solution that avoids moving argument handling out of subcommand files. |
As @jameshadfield alluded to in #1664 (comment), most of the startup time is spent on resolving imports. By running ![]() The run time of the Augur code was just 0.02 seconds reported by cProfile + snakeviz. ![]() |
Right, imports unnecessary to run the current command (or show the command's Relatedly, a standalone install of Nextstrain CLI is noticeably faster to start up than a non-standalone install, because its importing most of its dependencies from memory instead of the filesystem. Nextstrain CLI uses a roughly equivalent approach to subcommands and imports as Augur. I've previously mentioned this casually a few other times in various places, but it seems worth recording here. |
That's only a good comparison against an initial "cold start" of a non-standalone install. Subsequent invocations should also load dependencies from memory due to caching (at least on my computer), making the speed comparable to a standalone install: $ for i in {1..5}; do time ~/.micromamba/envs/nextstrain-cli/bin/nextstrain --help >/dev/null; done
0.39s user 0.10s system 24% cpu 2.049 total
0.25s user 0.05s system 98% cpu 0.302 total
0.24s user 0.05s system 98% cpu 0.295 total
0.21s user 0.04s system 99% cpu 0.254 total
0.22s user 0.04s system 99% cpu 0.263 total
$ for i in {1..5}; do time ~/.nextstrain/cli-standalone/nextstrain --help >/dev/null; done
0.21s user 0.05s system 70% cpu 0.365 total
0.22s user 0.02s system 97% cpu 0.244 total
0.19s user 0.01s system 98% cpu 0.207 total
0.20s user 0.02s system 94% cpu 0.230 total
0.19s user 0.01s system 98% cpu 0.209 total The timing result in my previous comment was after a few consecutive runs, so most dependencies should have been loaded from memory. This is what I get after a fresh reboot: $ for i in {1..5}; do time ~/.micromamba/envs/nextstrain-augur/bin/augur --help >/dev/null; done
0.66s user 0.29s system 33% cpu 2.806 total
0.55s user 0.11s system 99% cpu 0.668 total
0.55s user 0.12s system 98% cpu 0.679 total
0.55s user 0.11s system 99% cpu 0.663 total
0.55s user 0.11s system 99% cpu 0.672 total |
Yeah, true, the disk page cache helps. But those pages are easily evicted if not frequently used, and each eviction "resets" the start up time. The non-standalone installs also incur more disk accesses (e.g. BTW, on Linux you can clear the disk caches without rebooting with either:
There is probably a similar method for macOS. (Also, to be clear, I'm totally not saying we should bundle Augur like we do Nextstrain CLI. I don't think we should!) |
Context
Currently on MacOS 10.15.3, the CLI is slow to display after typing
augur
.Description
Investigate if there is an optimization that can be made.
The text was updated successfully, but these errors were encountered: