- 
                Notifications
    
You must be signed in to change notification settings  - Fork 9
 
Open
Description
Preliminary: DiffResult objects must always be realiased when updated, as mentioned in the docs
https://juliadiff.org/DiffResults.jl/stable/#DiffResults.value!
In most cases it is unnecessary, because the result object itself gets mutated. However, it causes a heap allocation to create the mutable struct defined here:
DiffResults.jl/src/DiffResults.jl
Lines 19 to 25 in 724a23d
| mutable struct MutableDiffResult{O,V,D<:Tuple} <: DiffResult{O,V,D} | |
| value::V | |
| derivs::D # ith element = ith-order derivative | |
| function MutableDiffResult(value::V, derivs::NTuple{O,Any}) where {O,V} | |
| return new{O,V,typeof(derivs)}(value, derivs) | |
| end | |
| end | 
Here's a proof of concept: instead of the current code
DiffResults.jl/src/DiffResults.jl
Lines 156 to 157 in 724a23d
| value!(r::MutableDiffResult, x::Number) = (r.value = x; return r) | |
| value!(r::MutableDiffResult, x::AbstractArray) = (copyto!(value(r), x); return r) | 
we could instead return a new object every time
value!(r::MutableDiffResult, x::Number) = MutableDiffResult(x, r.derivs)
value!(r::MutableDiffResult, x::AbstractArray) = (copyto!(value(r), x); return r)- Would it decrease or increase the performance of the update? Don't know
 - Would it be considered a breaking change? Perhaps (see below)
 - Would it break stuff in practice? Definitely (see below)
 
Metadata
Metadata
Assignees
Labels
No labels