Skip to content

Commit 6bfce60

Browse files
authored
Reduce latency with a few precompiles (#863)
1 parent a017921 commit 6bfce60

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/StaticArrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,9 @@ include("deque.jl")
144144
include("flatten.jl")
145145
include("io.jl")
146146

147+
if Base.VERSION >= v"1.4.2"
148+
include("precompile.jl")
149+
_precompile_()
150+
end
151+
147152
end # module

src/precompile.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function _precompile_()
2+
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
3+
# These make a difference for Makie's TTFP and should help others too
4+
# Total time for this to run is ~2s. To time it, disable:
5+
# - the `_precompile_()` call in StaticArrays.jl
6+
# - the jl_generating_output line above
7+
# and then do
8+
# @time StaticArrays._precompile_()
9+
10+
for T in (Float32, Float64, Int) # some common eltypes
11+
for S = 2:4 # some common sizes
12+
L = S*S
13+
@assert precompile(Tuple{typeof(*),SMatrix{S, S, T, L},SMatrix{S, S, T, L}})
14+
@assert precompile(Tuple{typeof(inv),SMatrix{S, S, T, L}})
15+
@assert precompile(Tuple{typeof(transpose),SMatrix{S, S, T, L}})
16+
@assert precompile(Tuple{typeof(_adjoint),Size{(S, S)},SMatrix{S, S, T, L}})
17+
@assert precompile(Tuple{Core.kwftype(typeof(minimum)),NamedTuple{(:dims,), Tuple{Int}},typeof(minimum),SMatrix{S, S, T, L}})
18+
@assert precompile(Tuple{Core.kwftype(typeof(maximum)),NamedTuple{(:dims,), Tuple{Int}},typeof(maximum),SMatrix{S, S, T, L}})
19+
@assert precompile(Tuple{typeof(getindex),SMatrix{S, S, T, L},SOneTo{S-1},SOneTo{S-1}})
20+
end
21+
end
22+
23+
# Some expensive generators
24+
@assert precompile(Tuple{typeof(which(_broadcast,(Any,Size,Tuple{Vararg{Size}},Vararg{Any},)).generator.gen),Any,Any,Any,Any,Any,Any})
25+
@assert precompile(Tuple{typeof(which(_zeros,(Size,Type{<:StaticArray},)).generator.gen),Any,Any,Any,Type,Any})
26+
@assert precompile(Tuple{typeof(which(combine_sizes,(Tuple{Vararg{Size}},)).generator.gen),Any,Any})
27+
@assert precompile(Tuple{typeof(which(_mapfoldl,(Any,Any,Colon,Any,Size,Vararg{StaticArray},)).generator.gen),Any,Any,Any,Any,Any,Any,Any,Any})
28+
end

0 commit comments

Comments
 (0)