xzackli / Bolt.jl

differentiable boltzmann code
MIT License
43 stars 5 forks source link

why is RECFAST slow? #71

Closed xzackli closed 1 year ago

xzackli commented 2 years ago

The RECFAST implementation currently in Bolt should be on the order of milliseconds. What's happening?

jmsull commented 2 years ago

A little follow up:

using Bolt
𝕡 = CosmoParams()
bg = Background(𝕡; x_grid=-20.0:0.01:0.0 nq=15)
𝕣 = Bolt.RECFAST(bg=bg, Yp=𝕡.Y_p, OmegaB=𝕡.Ω_b)
ih = IonizationHistory(𝕣, 𝕡, bg)

#  42.092 μs (245 allocations: 13.47 KiB)
@btime Bolt.RECFAST(bg=bg, Yp=𝕡.Y_p, OmegaB=𝕡.Ω_b)
# 6.547 s (67790063 allocations: 6.93 GiB)
@btime IonizationHistory(𝕣, 𝕡, bg)

and the flamegraph:

Screen Shot 2022-09-13 at 15 49 09

jmsull commented 2 years ago

It looks like most of the solver time in the ionization ODEs is not actually in the stepping - it is in some dual-related stuff (first big block in the flamegraph). Also, that is a lot of allocations - next step is probably to look at profiler applied to ion_recfast!.

xzackli commented 2 years ago

Yeah, I suspected as much. I actually have a more optimized version prototyped -- I was trying to do the integration the right way using events in OrdinaryDiffEq.jl (gist).

jmsull commented 1 year ago

Closing this since you merged the recfaster branch