Skip to content

Commit 630d668

Browse files
authored
Add precompile directives (#17)
* Add precompile directives * version bump to v0.1.16 * don't speclialize deepcopy to reduce invalidations
1 parent e7a8de2 commit 630d668

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SphericalHarmonics"
22
uuid = "c489a379-e885-57ff-9236-bd896d33c250"
3-
version = "0.1.15"
3+
version = "0.1.16"
44

55
[deps]
66
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

src/SphericalHarmonics.jl

+18-15
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,22 @@ function Base.summary(io::IO, P::AssociatedLegendrePolynomials)
5252
end
5353
end
5454

55-
function Base.deepcopy_internal(S::SphericalHarmonicsCache, stackdict::IdDict)
56-
_C = Base.deepcopy_internal(S.C, stackdict)
57-
_P = Base.deepcopy_internal(S.P, stackdict)
58-
_Y = Base.deepcopy_internal(S.Y, stackdict)
59-
_SHT = Base.deepcopy_internal(S.SHType, stackdict)
60-
typeof(S)(_C, _P, _Y, _SHT)
61-
end
62-
63-
function Base.deepcopy_internal(P::AssociatedLegendrePolynomials, stackdict::IdDict)
64-
_cosθ = Base.deepcopy_internal(P.cosθ, stackdict)
65-
_lmax = Base.deepcopy_internal(P.lmax, stackdict)
66-
_P = Base.deepcopy_internal(P.P, stackdict)
67-
_initialized = Base.deepcopy_internal(P.initialized, stackdict)
68-
typeof(P)(_cosθ, _lmax, _P, _initialized)
69-
end
55+
# Optimized deepcopy, but this leads to a lot of invalidations
56+
#function Base.deepcopy_internal(S::SphericalHarmonicsCache, stackdict::IdDict)
57+
# _C = Base.deepcopy_internal(S.C, stackdict)
58+
# _P = Base.deepcopy_internal(S.P, stackdict)
59+
# _Y = Base.deepcopy_internal(S.Y, stackdict)
60+
# _SHT = Base.deepcopy_internal(S.SHType, stackdict)
61+
# typeof(S)(_C, _P, _Y, _SHT)
62+
#end
63+
64+
#function Base.deepcopy_internal(P::AssociatedLegendrePolynomials, stackdict::IdDict)
65+
# _cosθ = Base.deepcopy_internal(P.cosθ, stackdict)
66+
# _lmax = Base.deepcopy_internal(P.lmax, stackdict)
67+
# _P = Base.deepcopy_internal(P.P, stackdict)
68+
# _initialized = Base.deepcopy_internal(P.initialized, stackdict)
69+
# typeof(P)(_cosθ, _lmax, _P, _initialized)
70+
#end
7071

7172
function SphericalHarmonicsCache(T::Type, lmax::Int, ::Type{m_range}, SHType) where {m_range}
7273
C = compute_coefficients(T, lmax)
@@ -1130,4 +1131,6 @@ function sphericalharmonic(θ, ϕ, l::Integer, m::Integer, SHType::HarmonicType
11301131
norm * P
11311132
end
11321133

1134+
include("precompile.jl")
1135+
11331136
end

src/precompile.jl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
precompile(SphericalHarmonicsCache, (Type{Float64}, Int, Type{FullRange}, ComplexHarmonics))
2+
precompile(SphericalHarmonicsCache, (Type{Float64}, Int, Type{FullRange}, RealHarmonics))
3+
precompile(SphericalHarmonicsCache, (Type{Float64}, Int, Type{ZeroTo}, ComplexHarmonics))
4+
precompile(SphericalHarmonicsCache, (Type{Float64}, Int, Type{ZeroTo}, RealHarmonics))
5+
_S = SphericalHarmonicsCache(Float64, 0, FullRange, ComplexHarmonics())
6+
precompile(computePlmx!, (typeof(_S), Float64, Int))
7+
precompile(computePlmx!, (typeof(_S.P), Float64, Int))
8+
precompile(computePlmcostheta!, (typeof(_S), Float64, Int))
9+
precompile(computePlmcostheta!, (typeof(_S.P), Float64, Int))
10+
precompile(computeYlm!, (typeof(_S), Float64, Float64, Int))

0 commit comments

Comments
 (0)