Skip to content

Conversation

@jlaehne
Copy link
Contributor

@jlaehne jlaehne commented Jan 4, 2026

Description of the change

Import of LumiSpy is rather slow (1.6 s on linux) mainly due to the direct loading of Signal1D from HyperSpy. This PR uses __getattr__ as proposed by GitHub Copilot to load both the sub-modules and utility functions exposed at the top level of LumiSpy using a lazu approach.

Progress of the PR

  • Change implemented (can be split into several points),
  • [n/a] docstring updated (if appropriate),
  • [n/a] update user guide (if appropriate),
  • added tests -> existing tests run through,
  • add a changelog entry in the upcoming_changes folder (see upcoming_changes/README.rst),
  • Check formatting of the changelog entry (and eventual user guide changes) in the docs/readthedocs.org:lumispy build of this PR (link in github checks),
  • ready for review.

Minimal example of the bug fix or the new feature

import time, importlib

t0 = time.perf_counter()
importlib.import_module("lumispy")
print("import time:", time.perf_counter()-t0)

@jlaehne
Copy link
Contributor Author

jlaehne commented Jan 4, 2026

Failing tests should be fixed in #247

Copy link
Contributor

@ericpre ericpre left a comment

Choose a reason for hiding this comment

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

Is it worth adding test like in https://github.com/hyperspy/rosettasciio/blob/main/rsciio/tests/test_import.py?

Should lazy-loader be used to support typing and auto-completion in some development environment? This would add one more library but it is already a dependency of scikit-image and I also think that it will be good to use it in HyperSpy.

After hyperspy/hyperspy#3569 is merged, it will be possible to speed up signals import even more to 0.2-0.3s.

@ericpre
Copy link
Contributor

ericpre commented Jan 15, 2026

%time from lumispy.signals import CLSpectrum

takes 1.5 s on my laptop, while it should be possible to speed it up to ~0.3s.

@jlaehne
Copy link
Contributor Author

jlaehne commented Jan 15, 2026

takes 1.5 s on my laptop, while it should be possible to speed it up to ~0.3s.

With or without hyperspy/hyperspy#3569 ? Maybe we first see what that brings before we go too far in the optimization here. We should though maybe also split out the lazy signal versions like you just did in HyperSpy.

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