-
-
Notifications
You must be signed in to change notification settings - Fork 526
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
Speed up jrnl by 10%, improve slow imports #959
Conversation
Improve slow imports
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.
This looks great. Just a few small changes, and we should be good to go. Thank you!
) | ||
print("Exiting.", file=sys.stderr) | ||
sys.exit(1) | ||
if util.is_old_version(config_path): |
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 agree that this is good to break out into a separate function, but without also updating upgrade_jrnl_if_necessary
we now perform this check twice.
jrnl/util.py
Outdated
def is_config_json(config_path): | ||
with open(config_path, "r", encoding="utf-8") as f: | ||
config_file = f.read() | ||
if not config_file.strip().startswith("{"): |
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.
Nitpick:
if not condition:
return False
return True
can be more succinctly written as
return condition
Hi @wren , Thanks for your comments! I improved code in the last commit, check it, please :) |
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.
Thank you! 🏅
* Improve slow imports * Fix codestyle * fix twice version validation * Fix a syntax mistake
Hi!
I noticed, that jrnl starts with a slight delay. I researched code and found some slow and rare global imports.
I made rare imports local and added an additional function, which checks version of jrnl.
These improvements have boosted speed by 10% and have boosted python imports by 23%. I used
perf stat
andpython3 -X importtime
for analyzing.Perf stat on the develop branch:
Perf stat with my improvements:
And some screenshots for importtime measures
Develop: https://imgur.com/lk4AslE
My improvements: https://imgur.com/0snmcEo
Checklist
poetry run behave
black (consistent code styling). --
poetry run black --check . --verbose --diff
(logically errors and unused imports). --
poetry run pyflakes jrnl features
Pull Requests for the same update/change?
us to include them?