Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some major invalidations to improve compile times (#509)
* Fix some major invalidations to improve compile times Unitful.jl was flagged as a major invalidator of compilation downstream. Test: ```julia # From: https://timholy.github.io/SnoopCompile.jl/stable/snoopr/ using SnoopCompile invalidations = @Snoopr begin using DifferentialEquations function lorenz(du,u,p,t) du[1] = 10.0(u[2]-u[1]) du[2] = u[1]*(28.0-u[3]) - u[2] du[3] = u[1]*u[2] - (8/3)*u[3] end u0 = [1.0;0.0;0.0] tspan = (0.0,100.0) prob = ODEProblem(lorenz,u0,tspan) alg = Rodas5() tinf = solve(prob,alg) end; trees = SnoopCompile.invalidation_trees(invalidations); @show length(SnoopCompile.uinvalidated(invalidations)) # show total invalidations show(trees[end]) # show the most invalidated method ``` This method won the prize for the absolute most invalidations 🎉. But I think the bigger issue is that it simply doesn't follow Julia semantics. It fixes the types for issue #127 in a way that gives a stricter type than Julia would do in the normal cases (which is why the invalidation occurs). After this PR, heterogeneous arrays of numbers with Quantity in there act normally, and compile times are back to normal. Here's a showcase of it being normal: ```julia using Unitful, Test m = u"m" cm = u"cm" b = Union{Complex,Float64}[0 + 0im, 0.0] @test b + b == b @test b .+ b == b @test eltype(b+b) === Number b = Number[0 + 0im, 0.0] @test b + b == b @test b .+ b == b @test eltype(b+b) === Number b = [0.0, 0.0m] @test b + b == b @test b .+ b == b @test eltype(b+b) === Number ``` * Update promotion.jl
- Loading branch information
0d3b586
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, but is this enough? Adding b +b now changes the type.