JuliaDiff / JuliaDiff/DiffResults.jl

Does `MutableDiffResult` have to exist at all?

Open
#26 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
37
Forks
9
PR merge metrics
No merged PRs in 30d

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:

https://github.com/JuliaDiff/DiffResults.jl/blob/724a23d326353353aa78ae9b9e770685119492dc/src/DiffResults.jl#L19-L25

Here's a proof of concept: instead of the current code

https://github.com/JuliaDiff/DiffResults.jl/blob/724a23d326353353aa78ae9b9e770685119492dc/src/DiffResults.jl#L156-L157

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the value! documentation and the MutableDiffResult definition in src/DiffResults.jl at lines 19–25, then inspect the update code at lines 156–157. Compare the proposed behavior for scalar and array updates, and establish whether the change affects performance or compatibility. Done means a maintainer-approved decision on whether MutableDiffResult should remain and what API behavior is supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.