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

perf: refactor wizard to avoid expensive imports at CLI startup #615

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

joanise
Copy link
Member

@joanise joanise commented Dec 20, 2024

PR Goal?

On the login node on GPSC-C, the CLI can take 4 or 5 seconds to respond to a <tab> because it's loading a lot of stuff. The biggest culprits are typer, rich, and other things required to actually provide CLI help and autocompletion, but I noticed the wizard is doing some imports we can defer too, so I refactored it.

This results in a 15% or so speed up of everyvoice -h once already loaded from cache, and I'm not sure how much on a first try when not in disk cache yet (that's harder to measure!). Not the big difference I was hoping for, but still worth committing and pushing.

Plus, the refactored code is a little cleaner than the original imho.

Feedback sought?

Regular review

The diff will look huge, but it's not: stuff removed from wizard/__init__.py has been moved verbatim to wizard/tour.py.

Priority?

low

Tests added?

was already covered, adjusted where needed

How to test?

run everyvoice test cli and maybe everyvoice new-project and see no failures.

Confidence?

high: this is just moving definitions from one file to another, using VSCode's refactoring tools and then testing and adjusting the few little bits it didn't handle.

Note: I thought of having the Step classes in step.py and the Tour class in tour.py, but doing so created circular imports since each uses the other for typing hints, and therefore I decided it made most sense to keep them all together in tour.py.

Version change?

no

Related PRs?

Copy link

semanticdiff-com bot commented Dec 20, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  everyvoice/wizard/dataset.py  12% smaller
  everyvoice/tests/test_wizard.py  1% smaller
  everyvoice/tests/stubs.py  0% smaller
  everyvoice/tests/test_wizard_helpers.py  0% smaller
  everyvoice/wizard/__init__.py  0% smaller
  everyvoice/wizard/basic.py  0% smaller
  everyvoice/wizard/main_tour.py  0% smaller
  everyvoice/wizard/tour.py  0% smaller

Copy link
Contributor

CLI load time: 0:00.26
Pull Request HEAD: 65418307b7e88ec269384ed0cb620a67ed53e7ff
Imports that take more than 0.1 s:
import time: self [us] | cumulative | imported package
import time:      1027 |     102326 |     typer.main
import time:       289 |     121148 |   typer
import time:      7655 |     198155 | everyvoice.cli

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 17 lines in your changes missing coverage. Please review.

Project coverage is 76.77%. Comparing base (fc0dc20) to head (6541830).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
everyvoice/wizard/tour.py 92.70% 11 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #615      +/-   ##
==========================================
+ Coverage   76.74%   76.77%   +0.02%     
==========================================
  Files          46       47       +1     
  Lines        3445     3449       +4     
  Branches      470      470              
==========================================
+ Hits         2644     2648       +4     
  Misses        700      700              
  Partials      101      101              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@roedoejet roedoejet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - thanks Eric! I agree it makes sense to move stuff out of the init module. Moving things to tour.py makes sense to me. This PR looks good, and does seem to speed things up. Thanks!

@joanise joanise merged commit 3a74d7c into main Jan 7, 2025
6 checks passed
@joanise joanise deleted the dev.ej/refactor-wizard-perf branch January 7, 2025 16:29
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

Successfully merging this pull request may close these issues.

2 participants