-
Notifications
You must be signed in to change notification settings - Fork 146
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
use StaticArraysCore #599
use StaticArraysCore #599
Conversation
With these two PRs: julia> @time_imports using ForwardDiff
6.3 ms IrrationalConstants
0.9 ms DiffRules
2.7 ms StaticArraysCore
2.3 ms DiffResults
19.3 ms Preferences
1.2 ms OpenLibm_jll
0.3 ms NaNMath
0.1 ms Compat
82.6 ms ChainRulesCore
3.6 ms DocStringExtensions 68.58% compilation time
0.7 ms ChangesOfVariables
0.6 ms InverseFunctions
0.7 ms LogExpFunctions
0.3 ms JLLWrappers
2.9 ms OpenSpecFun_jll 76.75% compilation time
15.5 ms SpecialFunctions
27.6 ms MacroTools
0.3 ms CommonSubexpressions
101.4 ms ForwardDiff Before, StaticArrays completely dominates: julia> @time_imports using ForwardDiff
6.4 ms IrrationalConstants
0.7 ms DiffRules
2.4 ms StaticArraysCore
608.7 ms StaticArrays
2.4 ms DiffResults
20.7 ms Preferences
1.2 ms OpenLibm_jll
... |
CI gives errors like this, which don't show up when running simple examples locally:
|
My suspicion is that the type piracy in StaticArrays is actually a problem here: it defines functions (that it does not own) for types in StaticArraysCore (that it does not own) which are not available when the |
Yes that's my guess too. I did not try very hard to replicate locally, but I did use ForwardDiff first, before loading StaticArrays. Scrolling through it looks like all are from |
Yes, seems that might be sufficient for ForwardDiff. However, I guess these issues could also occur in other packages for different functions and hence ideally StaticArrays would fix these type piracies. |
The only way to fix (all of) them would be to merge the two packages again, no? |
Hmm, I am not familiar with the internals of StaticArrays but from a quick look it indeed seems that most of StaticArrays is type piracy currently - and hence, as far as I understand, potentially problematic when working with |
This seems to run counter to most of the point of having a *Core.jl package: the parent package must commit a great deal of type-piracy. For StaticArrays, it must be nearly 100% since most of its functionality comes from extending Base/stdlib functions. We could in principle put all |
Sure, I see that one has to commit type piracy somewhere, so the ideal I mentioned above won't be possible. However, with the current setup to me it seems that one can't use Base functionality of static arrays inside of Maybe that could be avoided for Base functions by moving all definitions with Base functions to StaticArraysCore (without stdlibs) but maybe already that would increase compilation and loading times of StaticArraysCore too much... |
It might be narrower than that. Functions which act on the instance can't be called until you have one, but functions which accept the type can be called outside the returned quote, and these are the problem. Minimal example: # Core package
struct M1 end
foo(x::Int) = x
# Foreign package
@generated function gen(x::T) where T
# :(foo(x)) # no problem
foo(x) # problem
# :(foo($T)) # no problem
end
gen(1)
# Big package
foo(::M1) = 33
foo(::Type{M1}) = 99
# User
gen(M1()) The problem code here uses ForwardDiff.jl/src/apiutils.jl Lines 21 to 25 in c6dc209
|
I think this is done. The above |
This could be made into an extension which would also solve the loading time. |
Maybe there would be less reason to create StaticArraysCore now that extensions exist. But unless there's a plan to deprecate the core package, maybe ForwardDiff may as well use it? The next heaviest thing is ChainRulesCore, which isn't directly loaded. Perhaps all the packages for which ForwardDiff defines rules out to extensions would be a good idea. |
Hah, just posted JuliaArrays/StaticArraysCore.jl#15. If people can agree on that plan, it might be easier to not port more packages to using |
Is it certain the extension feature will make 1.9? I see there are 22 packages using StaticArraysCore, but I suppose no problem to have some mixture of mechanisms for a while. |
It's on the backport branch at least. |
Closes #591. Should reduce loading time by a factor of 5 or so. Needs JuliaDiff/DiffResults.jl#22
Needs Julia 1.6.
What thoughts on dropping Julia 1.0 support that in a patch release?The version with #481 is not yet tagged. If that does throw up any surprises, then best to be able to make a patch release correcting them... so we should require Julia 1.6 before tagging that, rather than just after?Master is 0.11-DEV, and requires Julia 1.6.