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

Optimize imports #604

Open
danielgafni opened this issue Oct 24, 2024 · 5 comments
Open

Optimize imports #604

danielgafni opened this issue Oct 24, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@danielgafni
Copy link

danielgafni commented Oct 24, 2024

I've noticed pyserde contributes a fair share to my CLI app import time flamegraph (I'm using pyserde for app configuration so it has to be imported at top level).

Here is the breakdown for pyserde:

image

It's really nothing to worry about, but I guess dependencies like numpy and sqlalchemy could be imported in a lazy fashion in order to further improve import times.

This flamegraph can be made with tuna.

@yukinarit
Copy link
Owner

Hi @danielgafni!

Thanks for making a framegraph! I've never done this optimization.

Is it like moving all the imports to the code using it?

        elif is_numpy_array(c):
            from .numpy import deserialize_numpy_array_direct
            res = deserialize_numpy_array_direct(c, o)

@yukinarit yukinarit added the enhancement New feature or request label Oct 25, 2024
@danielgafni
Copy link
Author

danielgafni commented Oct 25, 2024

Yes exactly. If you need them for type annotations, you can do the following:

from typing import TYPE_CHECKING

if TYPE_CHECKING:  # will NOT be executed at runtime
    import numpy as np

def my_func(arg: "np.ndarray"):
    ...

@yukinarit
Copy link
Owner

Looks good!

Would you be able to contribute to pyserde? 🙂

@danielgafni
Copy link
Author

Maybe! I'm short on time right now but it should improve in a few weeks

@yukinarit
Copy link
Owner

awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants