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

MAINT: Use lazy_loader to speed up plopp first import #405

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

MridulS
Copy link
Member

@MridulS MridulS commented Jan 28, 2025

In the spirit of scipp/scippneutron#596, this adds lazy_loader to plopp.
Import time goes from

In [1]: %time import plopp
CPU times: user 234 ms, sys: 33.7 ms, total: 268 ms
Wall time: 343 ms

to

In [1]: %time import plopp
CPU times: user 3.52 ms, sys: 3.61 ms, total: 7.12 ms
Wall time: 7.15 ms

(not a very scientific comparison but still seems like a decent speedup).

The attach_stub function works by parsing the .pyi files to infer submodules and functions to expose. It also makes sure that static typecheckers and IDE don't complain too much.

'Camera',
'Node',
'View',
'backends',
Copy link
Member

Choose a reason for hiding this comment

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

Am I right that the backends is now gone from the __all__?
I don't know if it's important or not...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, it should be fine I think. As backends is still there explicitly in __init__.py.

It's not in the __all__ list but it is still accesible.

In [1]: import plopp

In [2]: plopp.backends
Out[2]: BackendManager({'2d': 'matplotlib', '3d': 'pythreejs'})

In [3]: 'backends' in plopp.__all__
Out[3]: False


from .graph import show_graph
from .helpers import node, widget_node
from .node_class import Node
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for renaming the node file to node_class? Was there a clash with something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, helpers.node was clashing with node.py

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should just move the Node and the helpers in a common file? (could be node.py or a differently named file).

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we do that in a new PR? I want to make this PR minimal so it's easy to revert in case this messes things up downstream.

@MridulS MridulS merged commit f43c626 into scipp:main Jan 29, 2025
4 checks passed
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