Skip to content

fix memory allocation regression of muladd introduced in v1.10 - #321

Merged
JeffreySarnoff merged 1 commit into
JuliaMath:mainfrom
ranocha:hr/allocations_muladd
Jul 28, 2026
Merged

fix memory allocation regression of muladd introduced in v1.10#321
JeffreySarnoff merged 1 commit into
JuliaMath:mainfrom
ranocha:hr/allocations_muladd

Conversation

@ranocha

@ranocha ranocha commented Jul 27, 2026

Copy link
Copy Markdown
Member

In version v1.10, allocations were introduced in muladd (and fma) for some inputs. The old (good) behavior is

julia -e 'using Pkg; Pkg.activate(temp = true); Pkg.add(name = "DoubleFloats", version = v"1.9.4"); using DoubleFloats; foo() = begin a = Double64(1.0); b = Double64(1.0); c = Double64(-1.0); return muladd(a, b, c); end; foo(); @show @allocated foo()'
[...]
#= none:1 =# @allocated(foo()) = 0

The new (bad) behavior in the current release is

julia -e 'using Pkg; Pkg.activate(temp = true); Pkg.add(name = "DoubleFloats", version = v"1.10.0"); using DoubleFloats; foo() = begin a = Double64(1.0); b = Double64(1.0); c = Double64(-1.0); return muladd(a, b, c); end; foo(); @show @allocated foo()'
[...]
#= none:1 =# @allocated(foo()) = 320

This PR fixes this performance regression. I used Codex to create this PR.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.53%. Comparing base (41c8746) to head (c503c27).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   69.45%   69.53%   +0.08%     
==========================================
  Files          57       57              
  Lines        3051     3056       +5     
==========================================
+ Hits         2119     2125       +6     
+ Misses        932      931       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ranocha

ranocha commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

@JeffreySarnoff Here are some additional benchmark results:

On current main:

julia> using BenchmarkTools, DoubleFloats

julia> function foo(x, y, z)
           a = Double64(x)
           b = Double64(y)
           c = Double64(z)
           return muladd(a, b, c)
       end
foo (generic function with 1 method)

julia> foo(1.0, 1.0, -1.0)
0.0

julia> @allocated foo(1.0, 1.0, -1.0)
320

julia> @benchmark foo($(Ref(1.0))[], $(Ref(1.0))[], $(Ref(-1.0))[])
BenchmarkTools.Trial: 10000 samples with 961 evaluations per sample.
 Range (min  max):   85.588 ns  986.472 ns  ┊ GC (min  max): 0.00%  89.84%
 Time  (median):      96.732 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   100.251 ns ±  28.831 ns  ┊ GC (mean ± σ):  2.16% ±  6.07%

     ▁▁   ▁  ▁▁▁▁▂▄▇█▇▅▄▄▅▅▃▃▂▂▃▃▂▂▁▁▂▂▁                        ▂
  ██████▇███████████████████████████████████▆▇▆▆▆▅▅▅▅▆▆▅▅▄▄▅▄▄▅ █
  85.6 ns       Histogram: log(frequency) by time        121 ns <

 Memory estimate: 320 bytes, allocs estimate: 4.

With this PR:

julia> using BenchmarkTools, DoubleFloats

julia> function foo(x, y, z)
           a = Double64(x)
           b = Double64(y)
           c = Double64(z)
           return muladd(a, b, c)
       end
foo (generic function with 2 methods)

julia> foo(1.0, 1.0, -1.0)
0.0

julia> @allocated foo(1.0, 1.0, -1.0)
0

julia> @benchmark foo($(Ref(1.0))[], $(Ref(1.0))[], $(Ref(-1.0))[])
BenchmarkTools.Trial: 10000 samples with 996 evaluations per sample.
 Range (min  max):  17.487 ns  42.630 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     20.164 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   20.400 ns ±  2.042 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

     ▆▅▃▅▂ ▁▁    ▁▅█▆▄▅▄▃▃▁▁▁▂▂   ▂▃▁    ▂▂     ▁▃▂           ▂
  ▄▄████████████▇██████████████▇▅▆████▇▇████▇▇▆▆████▇▇▇▆▆▇▆██ █
  17.5 ns      Histogram: log(frequency) by time      26.5 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

@JeffreySarnoff JeffreySarnoff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

giid

@JeffreySarnoff
JeffreySarnoff merged commit 433ad64 into JuliaMath:main Jul 28, 2026
7 checks passed
@JeffreySarnoff

JeffreySarnoff commented Jul 28, 2026 via email

Copy link
Copy Markdown
Member

@ranocha

ranocha commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Thanks a lot for ahndling this so quickly!

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.

2 participants