Skip to content

Conversation

@KristofferC
Copy link
Collaborator

@KristofferC KristofferC commented Nov 24, 2025

these often get quite large and the fact that they are non-mutable means Julia copies them which is quite expensive

Consider for example:

using ForwardDiff: ForwardDiff, HessianConfig, Chunk
using DiffResults

function test()
    x = rand(12)
    result = DiffResults.HessianResult(x)
    cfg = HessianConfig(sum, result, x, Chunk{12}())

    # Warmup
    ForwardDiff.hessian!(result, sum, x, cfg)

    @time ForwardDiff.hessian!(result, sum, x, cfg)

    @time for i in 1:100
        ForwardDiff.hessian!(result, sum, x, cfg)
    end
end

test()

Before this change it gives:

  0.000003 seconds (2 allocations: 16.000 KiB)
  0.000280 seconds (200 allocations: 1.562 MiB)

Now it instead gives

  0.000002 seconds (2 allocations: 160 bytes)
  0.000120 seconds (200 allocations: 15.625 KiB)

At some point, Julia might do this better.

these often get quite large and the fact that they are non-mutable means Julia copies them which is quite expensive
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

At some point, Julia might do this better.

That would be nice.

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