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

Is it possible to lazy load the repr handlers? #16

Open
laike9m opened this issue Nov 13, 2020 · 6 comments
Open

Is it possible to lazy load the repr handlers? #16

laike9m opened this issue Nov 13, 2020 · 6 comments

Comments

@laike9m
Copy link

laike9m commented Nov 13, 2020

When profiling my program, I find that importing cheap_repr is very expensive. Here's one profiling result using py-spy:

https://laike9m.github.io/images/af9b0d4.svg

image

Importing cheap_repr took ~8% of the total time. In __init__.py, it seems that it should be possible to make @try_register_repr calls lazy. Especially for registering Pandas handlers, they took most of the time. This becomes worse when users have Pandas installed but didn't really call cheap_repr on Pandas objects.

@alexmojaki
Copy link
Owner

I am interested in this (#3) but I don't know the best way to do it or how easy it would be. Happy to accept a PR. Since it seems like it requires an import hook it could be a Python 3 only enhancement.

@laike9m
Copy link
Author

laike9m commented Nov 13, 2020

I think it would be helpful to write down what you have in mind about import hooks, and we can see if somebody will have time to work on this.

@alexmojaki
Copy link
Owner

I'm imagining an import hook that is triggered whenever a module name that was registered with try_register_repr is imported for the first time, and only then is the repr registered against the actual class. So instead of importing pandas, it waits until someone else imports pandas, and at that moment registers the reprs for DataFrame etc.

it seems that it should be possible to make @try_register_repr calls lazy

What did you have in mind?

@laike9m
Copy link
Author

laike9m commented Nov 13, 2020

I was more thinking of doing reigsitering when it is actually used

@alexmojaki
Copy link
Owner

How?

@laike9m
Copy link
Author

laike9m commented Nov 13, 2020

I don't know if that's possible, I'll have to take a closer look at the code. It's just a thought for now.

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

No branches or pull requests

2 participants