-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
defining a few constructor methods gives 2x import slowdown #27599
Comments
Won't that invalidate any code that calls |
Only if you call the code with a |
Yes, but that also affects any highly generic call site like Unfortunately this is just a really difficult edge case --- you're not often able to write "here's a way to construct almost anything". |
Where possible, a better approach is to adapt PyObjects to interfaces expected by existing constructors and conversions, rather than adding new constructors. For example |
Currently I’m just defining convert methods and not constructors on 0.7 |
In updating PyCall for the latest Julia (JuliaPy/PyCall.jl#505), I noticed that dealing with #23273 led to a huge slowdown.
In particular, PyCall used to define only
convert(T, o::PyObject)
methods for converting Python objects to native Julia types, and I gotT(o)
constructors automatically. In updating, I first tried changing all of myconvert
methods to constructors, but this led to 30x (!) load-time slowdowns (after precompiling) on 0.6, and out-of-memory errors in Travis. Instead, I opted to leave theconvert
methods as-is.What I noticed is that, if I also add an explicit constructor that calls the
convert
method, to preserve the constructor API on 0.7, it led to a big slowdown in load time. In particular, just adding(at the end of
PyCall/src/conversions.jl
in my JuliaPy/PyCall.jl#505 branch) caused theusing PyCall
time (after precompiling) to slow down from 10s to 20s on my machine. (And it is 3.5s on 0.6, so there are other slowdowns too.)It is a little disturbing that adding 4 lines to a file can slow down loading by 10 seconds, so I thought someone might want to look into this. (I'm guessing that there is some performance gotcha associated with defining new constructors for very common types like
Number
.)The text was updated successfully, but these errors were encountered: