-
Notifications
You must be signed in to change notification settings - Fork 2k
Import speedups #7122
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
Import speedups #7122
Conversation
|
This is awesome. Thanks for poking around here @mbargull. |
|
Let's see how the upstream patch goes, and then decide what to do about |
|
Note this is targeted at master, which is conda 4.6. I don't think that's an issue. I'd like to get 4.6 release relatively soon. What would mark a 4.6 release is the inclusion of #6518. |
|
Also, just throwing this out there... Seems like the world is moving toward toml. Wonder what it would look like for us to start to handle both yaml and toml, eventually moving away from yaml? Just a thought... |
|
Is it worth mucking around with conda/conda/common/serialize.py Line 28 in 31130cd
to try to lazy-load that? Basically lazy-load any ruamel.yaml import. It would help users with no yaml configuration at all. I'm not sure if it's worth it or not... |
|
BTW, how did you generate that report? It's very nice. Mind sharing the code? |
kalefranz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this PR as-is. Maybe in the future we could look at lazy-loading ruamel.yaml as a whole, but not all users will benefit from that, so I'm fine not adding in that complexity also.
Yeah, I agree with "not sure if it's worth it or not" and "I'm fine not adding in that complexity also." 😉
Nothing fancy really, just a little home-brewed script: #!/usr/bin/env python
from __future__ import print_function
from itertools import chain
from os import system
from timeit import repeat
repeats = 1000
row_sep = "-"
col_sep = "|"
percentiles = (0, .25, .5, .75, 1)
shell_commands = (
"true",
"python -c 'pass'",
*(
"python -c 'import {}'".format(module)
for module in (
"conda",
"conda.base",
"conda.common",
"inspect",
"urllib",
"urllib.request",
"conda._vendor",
"conda._vendor.toolz",
"conda._vendor.toolz.functoolz",
)
),
*(chain.from_iterable(
(
"""python -c 'import re'""".format(module),
"""python -c 'import {}'""".format(module),
"""python -c 'import re; dummy=re.compile(""); re.compile = lambda *args: dummy; import {}'""".format(module),
)
for module in ("ruamel_yaml",)
)),
)
def to_percentile_string(values, percentiles=percentiles):
values = sorted(values)
percentile_values = (values[int(p * (len(values)-1))] for p in percentiles)
return " ".join("{:9.5f}".format(v) for v in percentile_values)
for shell_command in shell_commands:
times = repeat(lambda: system(shell_command), number=1, repeat=repeats)
print(to_percentile_string(times), col_sep, shell_command)
print(row_sep * len(to_percentile_string((0,))), col_sep, row_sep * max(map(len, shell_commands)), sep=row_sep) |
https://pypi.org/project/ruamel.yaml/0.15.39/#changelog
🎉 |
|
Since y'all liked the quartiles of measured run times so much, here are some new ones: TLDR; full output:
|
|
Really nice work, @mbargull. Thanks. |
|
Hi there, thank you for your contribution to Conda! This pull request has been automatically locked since it has not had recent activity after it was closed. Please open a new issue or pull request if needed. |
conda's startup time is heavily influenced by some costly imports of external modules.This PR alone cuts the overall import time of
conda.base.contextby approx. 25 % (usingconda 4.5.0+python 3.6.5).One costly import we cannot avoid is
ruamel.yaml/ruamel_yaml. 1/3 of the import time* of that package is spent compiling regular expression (of which usually only few are actually used). We could monkeypatchre.compileto avoid this, but the saner approach is of course to fix this upstream. This is done in https://bitbucket.org/ruamel/yaml/pull-requests/27/improve-package-import-time/diff.If that
ruamel.yamlPR gets accepted, the overall time savings combined with this PR would be approx. 33 %.