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

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

joanise merged 1 commit into main from dev.ej/refactor-wizard-perf
joanise
joanise100 days ago

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?

joanise perf: refactor wizard to avoid expensive imports at CLI startup
65418307
semanticdiff-com
semanticdiff-com100 days ago (edited 100 days ago)

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
joanise joanise requested a review from SamuelLarkin SamuelLarkin 100 days ago
joanise joanise requested a review from roedoejet roedoejet 100 days ago
github-actions
github-actions100 days ago
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

codecov
codecov99 days ago (edited 82 days ago)

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.

roedoejet
roedoejet approved these changes on 2025-01-07
roedoejet82 days ago

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 3a74d7cb into main 82 days ago
joanise joanise deleted the dev.ej/refactor-wizard-perf branch 82 days ago

Login to write a write a comment.

Login via GitHub

Assignees
No one assigned
Labels
Milestone