jmert / AssociatedLegendrePolynomials.jl

A library for calculating the Associated Legendre polynomials
https://jmert.github.io/AssociatedLegendrePolynomials.jl/
MIT License
20 stars 2 forks source link

Make use of mutable struct rather than Ref wrapper #1

Closed jmert closed 4 years ago

jmert commented 4 years ago

A past implementation made use of Base.RefValues to allow assignment of scalar values from within a shared function, but as the base implementation has gotten more complicated (especially with respect to using broadcasted operations), the fact that RefValue is not a subtype of AbstractArray required a wrapper type to obtain the semantics we required.

Since that time, the scalar calculation performance has suffered due to extra allocations and indirections in code path. At this point, it is now more performant to simply use a mutable struct than an immutably-wrapped RefValue.

Before this change:

julia> @btime legendre(LegendreSphereNorm(), 3000, 2, cosd(0.25));
  96.858 μs (12 allocations: 192 bytes)

With this change:

julia> @btime legendre(LegendreSphereNorm(), 3000, 2, cosd(0.25));
  19.251 μs (6 allocations: 96 bytes)
codecov[bot] commented 4 years ago

Codecov Report

Merging #1 into master will increase coverage by 2.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #1      +/-   ##
==========================================
+ Coverage   96.06%   98.07%   +2.01%     
==========================================
  Files           9       10       +1     
  Lines         254      260       +6     
==========================================
+ Hits          244      255      +11     
+ Misses         10        5       -5     
Impacted Files Coverage Δ
src/Legendre.jl 100.00% <ø> (ø)
src/calculation.jl 98.34% <100.00%> (+3.69%) :arrow_up:
src/scalar.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8a3b801...831659f. Read the comment docs.