Skip to content

The fitters should be imported lazily to save import time #336

Open

Description

@henrikjacobsenfys

The majority of the import time for core is importing fitters, because __init__ imports them via its import of easyscience.fitting.

So from easyscience.variable import Parameter also imports the fitters, which is a waste of import time.

We can instead check if the engines are there using

importlib.util.find_spec('lmfit') is not None etc, and updater the __init__ of minimizers to import lazily.

Activity

  1. added
    [scope] maintenance
    [priority] medium
    on Oct 21, 2026
  2. damskii9992 commented on Oct 21, 2026

    @damskii9992
    Contributor

    But is it a problem? Is our import time currently too long?

  3. henrikjacobsenfys commented on Oct 21, 2026

    @henrikjacobsenfys
    MemberAuthor

    But is it a problem? Is our import time currently too long?

    It takes a full second to import Parameter when it could be 0.1 second. Over the course of a day that can easily add up to multiple seconds! https://xkcd.com/1205/

  4. rozyczko commented on Oct 21, 2026

    @rozyczko
    Member

    Or we could just wait for Python 3.15, with its explicit lazy imports (like lazy import Parameter).
    https://astral.sh/blog/python-3.15#lazy-imports

  5. markbujehein commented on Oct 21, 2026

    @markbujehein
    Collaborator

    I was just thinking about this today! I noticed Plopp is using the lazy_loader packages, but this is way more exciting!
    There's also support for filtering

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] medium[scope] maintenance

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions