diff --git a/Project.toml b/Project.toml index e7229f2e..0addc92e 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ version = "1.6.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" @@ -15,8 +16,9 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StaticArraysStatisticsExt = "Statistics" [compat] -julia = "1.6" +PrecompileTools = "1" StaticArraysCore = "~1.4.0" +julia = "1.6" [extras] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" diff --git a/src/StaticArrays.jl b/src/StaticArrays.jl index fad003ae..0e4b1afe 100644 --- a/src/StaticArrays.jl +++ b/src/StaticArrays.jl @@ -19,6 +19,8 @@ import LinearAlgebra: transpose, adjoint, dot, eigvals, eigen, lyap, tr, normalize!, Eigen, det, logdet, logabsdet, cross, diff, qr, \ using LinearAlgebra: checksquare +using PrecompileTools + # StaticArraysCore imports # there is intentionally no "using StaticArraysCore" to not take all symbols exported # from StaticArraysCore to make transitioning definitions to StaticArraysCore easier. @@ -136,6 +138,5 @@ include("pinv.jl") end include("precompile.jl") -_precompile_() end # module diff --git a/src/precompile.jl b/src/precompile.jl index 439b53ac..e0737110 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -1,35 +1,29 @@ -function _precompile_() - ccall(:jl_generating_output, Cint, ()) == 1 || return nothing - # These make a difference for Makie's TTFP and should help others too - # Total time for this to run is ~2s. To time it, disable: - # - the `_precompile_()` call in StaticArrays.jl - # - the jl_generating_output line above - # and then do - # @time StaticArrays._precompile_() - - for T in (Float32, Float64, Int) # some common eltypes - for S = 2:4 # some common sizes - L = S*S - @assert precompile(Tuple{typeof(*),SMatrix{S, S, T, L},SMatrix{S, S, T, L}}) - @assert precompile(Tuple{typeof(*),SMatrix{S, S, T, L},SVector{S, T}}) - @assert precompile(Tuple{typeof(inv),SMatrix{S, S, T, L}}) - @assert precompile(Tuple{typeof(transpose),SMatrix{S, S, T, L}}) - @assert precompile(Tuple{typeof(_adjoint),Size{(S, S)},SMatrix{S, S, T, L}}) - @assert precompile(Tuple{Core.kwftype(typeof(minimum)),NamedTuple{(:dims,), Tuple{Int}},typeof(minimum),SMatrix{S, S, T, L}}) - @assert precompile(Tuple{Core.kwftype(typeof(maximum)),NamedTuple{(:dims,), Tuple{Int}},typeof(maximum),SMatrix{S, S, T, L}}) - @assert precompile(Tuple{typeof(getindex),SMatrix{S, S, T, L},SOneTo{S-1},SOneTo{S-1}}) +@setup_workload begin + @compile_workload begin + for T in (Float32, Float64, Int) # some common eltypes + for S = 2:4 # some common sizes + L = S*S + x = fill(0., SMatrix{S, S, T, L}) + x * x + y = fill(0., SVector{S, T}) + x * y + inv(x) + transpose(x) + _adjoint(Size(S, S), x) + minimum(x; dims=1) + minimum(x; dims=2) + maximum(x; dims=1) + maximum(x; dims=2) + getindex(x, SOneTo(S-1), SOneTo(S-1)) + y .* x .* y' + zero(y) + zero(x) + end end - end - # TODO: These fail to precompile on v1.11 pre-release - if VERSION < v"1.11.0-0" - # Some expensive generators - @assert precompile(Tuple{typeof(which(__broadcast,(Any,Size,Tuple{Vararg{Size}},Vararg{Any},)).generator.gen),Any,Any,Any,Any,Any,Any}) - @assert precompile(Tuple{typeof(which(_zeros,(Size,Type{<:StaticArray},)).generator.gen),Any,Any,Any,Type,Any}) - @assert precompile(Tuple{typeof(which(_mapfoldl,(Any,Any,Colon,Any,Size,Vararg{StaticArray},)).generator.gen),Any,Any,Any,Any,Any,Any,Any,Any}) - end - # broadcast_getindex - for m = 0:5, n = m:5 - @assert precompile(Tuple{typeof(broadcast_getindex),NTuple{m,Int},Int,CartesianIndex{n}}) + # broadcast_getindex + for m = 0:5, n = m:5 + broadcast_getindex(Tuple(1:m), 1, CartesianIndex(n)) + end end end