Skip to content

Conversation

hersle
Copy link
Contributor

@hersle hersle commented Jun 27, 2025

During profiling of ODEProblem in this example of my package, I found I saw being slowed down a lot by the line that calls default_toterm on every element in keys(defs) for every iteration in the loop, which I think could simply be precomputed before the loop.

using SymBoltz # https://github.com/hersle/SymBoltz.jl
using BenchmarkTools
M = ΛCDM() # a big System
Ms = mtkcompile(M)
pars = SymBoltz.parameters_Planck18(M) # some sym-to-num parameter dict
pars[M.k] = 1.0
@btime prob = ODEProblem(Ms, pars, (0.0, 10.0))

Before PR:

  2.607 s (27144415 allocations: 803.71 MiB)

After PR:

  995.616 ms (9386044 allocations: 317.20 MiB)

These changes give me a 3x speedup in construction of a big problem, and I think the logic should be equivalent before and after.

@hersle
Copy link
Contributor Author

hersle commented Jun 28, 2025

One more

  717.067 ms (8363734 allocations: 280.19 MiB)

Copy link
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for noticing this!

@AayushSabharwal
Copy link
Member

Waiting on SciML/NonlinearSolve.jl#634 to rerun CI

@hersle
Copy link
Contributor Author

hersle commented Jul 1, 2025

Re-run now and, if problem-free, get this in before the next release? 😃 @AayushSabharwal

@ChrisRackauckas ChrisRackauckas merged commit f0f412b into SciML:master Jul 2, 2025
99 of 127 checks passed
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.

3 participants