SciML / SciML/RecursiveArrayTools.jl
Excessive allocations with VectorOfArray in broadcast
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 233
- Forks
- 76
- Avg merge
- 2h 17m
- Merged PRs (30d)
- 9
Description
I am using a VectorOfArray as state vector in DifferentialEquations. This leads to too many allocations.
using DifferentialEquations
using RecursiveArrayTools
# Set up the state vector
U = VectorOfArray([zeros(100,100,100), zeros(100,100,100)]);
rhs!(U̇, U, p, t) = U̇ .= U
# Compile all code
prob = ODEProblem(rhs!, U, (0.0, 1.0));
sol = solve(prob, RK4(); adaptive=false, dt=1.0);
# Benchmark
prob = ODEProblem(rhs!, U, (0.0, 1.0));
@time sol = solve(prob, RK4(); adaptive=false, dt=1.0);
This outputs
1.639028 seconds (42.00 M allocations: 991.828 MiB, 18.67% gc time)
Note the very large number of allocations. It seems as if some operation was performing one small allocation per array element.
(I notice that this problem disappears if I switch to the midpoint rule.)
I tried with both Julia 1.7 and the current release branch of Julia 1.8.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reported VectorOfArray reproducer with DifferentialEquations, ODEProblem, RK4, and the rhs! benchmark, then compare it with the midpoint rule. Trace the allocations during the solve and identify the operation responsible for the per-element allocations; done means the RK4 case no longer shows excessive allocations while retaining the reported solve behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100