Skip to content
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

Move to PrecompileTools #1187

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/StaticArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -136,6 +138,5 @@ include("pinv.jl")
end

include("precompile.jl")
_precompile_()

end # module
56 changes: 25 additions & 31 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -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
Loading