-
-
Notifications
You must be signed in to change notification settings - Fork 688
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
Improve import startup time #2073
Comments
It gives an interesting boost performance that’s very useful when auto-reloading is enabled. Related to Kozea/WeasyPrint#2073.
Hi!
Yes, it’s slow.
Hacking imports (as you did in #2074) is possible, but it requires extra workarounds for many use cases: typing, tests, lint, submodule imports, API discovery, IDEs, etc. When Wouldn’t it be easier to lazy load WeasyPrint in your application? Or maybe include this in Django-WeasyPrint, where the lazy load is probably easier to implement than in WeasyPrint? (That’s actually a great idea, here we go: Kozea/Flask-WeasyPrint@6604003 😄) |
Hi, lazy loading Imo the ideal solution would be to have this "fix" in |
That’s good news. Do you use Django-WeasyPrint?
Yes, thanks for taking care of that, but I’m sure that other issues will appear if I merge this PR!
I agree, it’d be better, but unfortunately there’s no easy solution for that. For now, I’d prefer to have it in Django-WeasyPrint, Flask-WeasyPrint, and other web app libraries where it could be useful: the implementation is straightforward and much easier to maintain. Even better, we could have this one day in Python. PEP-690 has been rejected, but who knows… |
Just plain vanilla
This PEP was interesting indeed, I'll have to check why it was rejeceted. Thanks, closing the issue and related PR. |
On my machine, importing
weasyprint
takes more that half a second:Which can get annoying e.g. when running a Django server in dev. with autoreload. Did a bit of profiling to see where it was coming from1:
And it seems to be spread across different modules.
I will propose a workaround in a follow up PR, although there isn't only one way to deal with this so open to alternatives
Footnotes
python -X importtime -c 'import weasyprint' 2> import.log && tuna import.log
↩The text was updated successfully, but these errors were encountered: