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

Make most modules lazy load #1065

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

cafeclimber
Copy link
Contributor

@cafeclimber cafeclimber commented May 6, 2024

Addresses #1057. On my machine, import times were reduced from over 1 second to about 0.3 seconds.

@github-actions github-actions bot added Documentation Request/Improvement of the documentation TransmissionLines ContinuousIntegration labels May 7, 2024
@cafeclimber
Copy link
Contributor Author

Ok I think I super broke this PR trying to pull in the most recent changes. Happy to fix just lmk!

@FranzForstmayr
Copy link
Collaborator

would be great if possible :)

@github-actions github-actions bot removed Documentation Request/Improvement of the documentation TransmissionLines ContinuousIntegration labels May 7, 2024
@cafeclimber
Copy link
Contributor Author

would be great if possible :)

Okay I think that did it lol. Just gonna wait for the CI

@FranzForstmayr
Copy link
Collaborator

I think most of the linter issues can be fixed with ruff check . --fix

@cafeclimber
Copy link
Contributor Author

Hmmmm...I'm not sure why only 3.9 is failing. Specifically something about the matplotlib import

@FranzForstmayr
Copy link
Collaborator

I think all the calibration Test should run without matpotlib installed but it's imported somewhere.

@cafeclimber
Copy link
Contributor Author

Ah it was me being a dingus and not understanding how lazy_loader deals with missing imports. Seems ok now?

@FranzForstmayr
Copy link
Collaborator

Probably related: librosa/librosa#1721

@cafeclimber
Copy link
Contributor Author

Ah dang this seems like a deep problem. Matplotlib is easily the most time consuming import. At worst a fix might be to just move plotting imports to those specific functions that use them to avoid issues associated with using lazy_loader with mpl

@jhillairet jhillairet linked an issue May 10, 2024 that may be closed by this pull request
@@ -3,10 +3,9 @@
implemented in Python.
"""

__version__ = '1.0.0'
__version__ = "1.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity: why the change from ' to " for the strings? I always thought Python does accept both notations. Is it personal taste or a new general rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's almost certainly ruff's auto formatting. I try to avoid noisy commits that are primarily changes due to auto formatting but sometimes stuff slips by 😮‍💨

@FranzForstmayr
Copy link
Collaborator

Seems like the root cause:
scientific-python/lazy_loader#55

matplotlib is currently not compatible with lazy_load

@cafeclimber
Copy link
Contributor Author

Yeah I think the solution is to try to move all mpl-related imports into the methods that use them so they get deferred until then. Will be a bit clunky but the speed up is significant. I'll try to push something today

@jhillairet
Copy link
Member

How about this PR ? Would be nice to include it in the next version, to be released soon.

@cafeclimber
Copy link
Contributor Author

Hey sorry got caught up with dissertation work. Will make edits tonight to remove the lazy load module and move mpl imports into the respective plotting functions. Think that's the best we can do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing scikit-rf imports many modules and is slow
4 participants