Skip to content

Conversation

@DanielVandH
Copy link
Member

@DanielVandH DanielVandH commented Oct 31, 2025

Relies on JuliaArrays/LazyArrays.jl#386. Don't think the performance in the simple benchmark below is affected by JuliaArrays/LazyArrays.jl#383

Puts the MulAddAccumulate's cache_filldata! method behind a function barrier, cutting the number of allocations roughly in half for a very simple example. On current release:

using LazyArrays, SemiclassicalOrthogonalPolynomials, BenchmarkTools, InfiniteArrays
using SemiclassicalOrthogonalPolynomials: MulAddAccumulate
@benchmark copyto!(dest, src) setup=begin
    A = Vcat(1, cache(2:3), cache(4:∞))
    B = Vcat(cache(1:5), [1, 2], cache(3:∞))
    src = view(MulAddAccumulate(A, B), 1:100_000)
    dest = similar(src)
end

BenchmarkTools.Trial: 123 samples with 1 evaluation per sample.
 Range (min  max):  36.005 ms  72.708 ms  ┊ GC (min  max): 0.00%  3.77%
 Time  (median):     38.956 ms              ┊ GC (median):    4.51%
 Time  (mean ± σ):   40.786 ms ±  5.312 ms  ┊ GC (mean ± σ):  4.01% ± 2.82%

      ▂█▁
  ▃▄▃▃███▅▄▃▃▆▂▃▂▁▂▃▂▁▂▂▁▂▃▂▁▁▂▁▁▁▁▂▁▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▁▁▁▁▂▁▁▁▂ ▂
  36 ms           Histogram: frequency by time          65 ms <

 Memory estimate: 19.16 MiB, allocs estimate: 797057.

On this PR:

BenchmarkTools.Trial: 142 samples with 1 evaluation per sample.
 Range (min  max):  31.669 ms  48.247 ms  ┊ GC (min  max): 0.00%  5.63%
 Time  (median):     35.093 ms              ┊ GC (median):    6.51%
 Time  (mean ± σ):   35.255 ms ±  2.779 ms  ┊ GC (mean ± σ):  4.34% ± 3.45%

     ▄▁▂      ▇██▅
  ▄▃▆████▅▃▅▅▆█████▅▄▃▃▃▃▁▅▁▄▁▁▃▄▃▃▁▁▁▁▃▁▁▁▁▁▁▁▁▁▃▁▁▁▃▁▁▁▁▁▁▄ ▃
  31.7 ms         Histogram: frequency by time          47 ms <

 Memory estimate: 17.68 MiB, allocs estimate: 399625.

Doesn't really end up making as much of a difference inside divdiff for a HalfWeighted{:a} polynomial though, e.g.

@benchmark D[1:n, 1:n] setup = begin
    P = SemiclassicalJacobi(2.0, 1 / 2, 0, 1 / 2);
    Q = SemiclassicalOrthogonalPolynomials.HalfWeighted{:a}(P);
    D = diff(Q).args[2];
    n = 1000;
end

gives roughly the same results. Still need to make some performance improvements there as discussed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants