From 450c5c05dffa5d98d6d3197e90f42711c3fa0b93 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 17 Jul 2023 15:10:27 -0400 Subject: [PATCH 1/3] move to PrecompileTools . --- Project.toml | 4 +++- src/StaticArrays.jl | 3 ++- src/precompile.jl | 54 ++++++++++++++++++++------------------------- 3 files changed, 29 insertions(+), 32 deletions(-) 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..f58cbd96 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) + # @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}}) + getindex(x, SOneTo(S-1), SOneTo(S-1)) + 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}}) + # @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}) + + # broadcast_getindex + for m = 0:5, n = m:5 + broadcast_getindex(Tuple(1:m), 1, CartesianIndex(n)) + end end end From ef259d04b25254d877268ce95f7abb29b2d0c4f9 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 19 Jul 2023 10:27:50 -0400 Subject: [PATCH 2/3] update disabled precompiles Co-Authored-By: Tim Holy --- src/precompile.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/precompile.jl b/src/precompile.jl index f58cbd96..6dbec10e 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -10,17 +10,17 @@ inv(x) transpose(x) _adjoint(Size(S, S), x) - # @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}}) + 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' + zeros(y) + zeros(x) end end - # 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}) - # broadcast_getindex for m = 0:5, n = m:5 broadcast_getindex(Tuple(1:m), 1, CartesianIndex(n)) From 3f9d303f3f907e4fce08ca55c5f651b398ed30f9 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 19 Jul 2023 12:14:03 -0400 Subject: [PATCH 3/3] fix Co-Authored-By: Tim Holy --- src/precompile.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/precompile.jl b/src/precompile.jl index 6dbec10e..e0737110 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -16,8 +16,8 @@ maximum(x; dims=2) getindex(x, SOneTo(S-1), SOneTo(S-1)) y .* x .* y' - zeros(y) - zeros(x) + zero(y) + zero(x) end end