From c0cfe1e26aa9c4048c7d2fef89fd22c6dff4ed86 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 14:45:36 +1300 Subject: [PATCH 01/12] Fix allocation tests for Julia v1.12.5 --- test/broadcast.jl | 7 ++++++- test/utilities.jl | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/broadcast.jl b/test/broadcast.jl index 53b57ee..2e67d2e 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -31,7 +31,12 @@ end @test y == 5 # FIXME This should not allocate but I couldn't figure out where these # allocations come from. - n = (VERSION >= v"1.11" ? 42 : 30) * sizeof(Int) + n = ifelse( + VERSION >= v"1.12.5", + 36, + ifelse(VERSION >= v"1.11", 42, 30), + ) + n *= sizeof(Int) alloc_test(() -> MA.broadcast!!(+, a, b), n) alloc_test(() -> MA.broadcast!!(+, a, c), 0) end diff --git a/test/utilities.jl b/test/utilities.jl index eb8c5c3..f7c6f49 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -7,9 +7,7 @@ include("dummy.jl") # Allocating size for allocating a `BigInt`. Half size on 32-bit. -const BIGINT_ALLOC = @static if VERSION >= v"1.12-beta1" - Sys.WORD_SIZE == 64 ? 72 : 36 -elseif VERSION >= v"1.11" +const BIGINT_ALLOC = @static if VERSION >= v"1.11" Sys.WORD_SIZE == 64 ? 56 : 28 else Sys.WORD_SIZE == 64 ? 48 : 24 From 5832ae1a5241b9b0cd315df3ae2941fc518c6feb Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 14:47:03 +1300 Subject: [PATCH 02/12] Fix formatting --- test/broadcast.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/broadcast.jl b/test/broadcast.jl index 2e67d2e..c403154 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -31,11 +31,7 @@ end @test y == 5 # FIXME This should not allocate but I couldn't figure out where these # allocations come from. - n = ifelse( - VERSION >= v"1.12.5", - 36, - ifelse(VERSION >= v"1.11", 42, 30), - ) + n = ifelse(VERSION >= v"1.12.5", 36, ifelse(VERSION >= v"1.11", 42, 30)) n *= sizeof(Int) alloc_test(() -> MA.broadcast!!(+, a, b), n) alloc_test(() -> MA.broadcast!!(+, a, c), 0) From e8f838b430d83c41f05b133843bf3f358b5d210e Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 14:55:41 +1300 Subject: [PATCH 03/12] Update --- test/broadcast.jl | 4 +--- test/utilities.jl | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/broadcast.jl b/test/broadcast.jl index c403154..7798b34 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -31,9 +31,7 @@ end @test y == 5 # FIXME This should not allocate but I couldn't figure out where these # allocations come from. - n = ifelse(VERSION >= v"1.12.5", 36, ifelse(VERSION >= v"1.11", 42, 30)) - n *= sizeof(Int) - alloc_test(() -> MA.broadcast!!(+, a, b), n) + alloc_test_le(() -> MA.broadcast!!(+, a, b), 42 * sizeof(Int)) alloc_test(() -> MA.broadcast!!(+, a, c), 0) end diff --git a/test/utilities.jl b/test/utilities.jl index f7c6f49..78ba88d 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -15,10 +15,14 @@ end function alloc_test(f, n) f() # compile - @test n == @allocated f() + y = @allocated f() + @test n == y + return end function alloc_test_le(f, n) f() # compile - @test n >= @allocated f() + y = @allocated f() + @test n >= y + return end From 90729e4b863ebe128ea5542cbcdac9edb761aff3 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 15:12:16 +1300 Subject: [PATCH 04/12] Update --- test/utilities.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/utilities.jl b/test/utilities.jl index 78ba88d..f36e5a6 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -7,11 +7,7 @@ include("dummy.jl") # Allocating size for allocating a `BigInt`. Half size on 32-bit. -const BIGINT_ALLOC = @static if VERSION >= v"1.11" - Sys.WORD_SIZE == 64 ? 56 : 28 -else - Sys.WORD_SIZE == 64 ? 48 : 24 -end +const BIGINT_ALLOC = sizeof(Int) + @allocated BigInt(1) function alloc_test(f, n) f() # compile From f8c7679cb2087c4df8152ea3aac5ee5a916efd90 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 15:19:05 +1300 Subject: [PATCH 05/12] Update --- test/utilities.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/utilities.jl b/test/utilities.jl index f36e5a6..8a2f5af 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -7,7 +7,10 @@ include("dummy.jl") # Allocating size for allocating a `BigInt`. Half size on 32-bit. -const BIGINT_ALLOC = sizeof(Int) + @allocated BigInt(1) +const BIGINT_ALLOC = let + sizeof(Int) + @allocated(BigInt(1)) +end +@show BIGINT_ALLOC function alloc_test(f, n) f() # compile From 912caec5cdbd837a25504b91a997364d8664219e Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 15:25:55 +1300 Subject: [PATCH 06/12] Update --- test/broadcast.jl | 3 ++- test/utilities.jl | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/broadcast.jl b/test/broadcast.jl index 7798b34..ba7858a 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -31,7 +31,8 @@ end @test y == 5 # FIXME This should not allocate but I couldn't figure out where these # allocations come from. - alloc_test_le(() -> MA.broadcast!!(+, a, b), 42 * sizeof(Int)) + n = 6 * @allocated(BigInt(1)) + alloc_test(() -> MA.broadcast!!(+, a, b), n) alloc_test(() -> MA.broadcast!!(+, a, c), 0) end diff --git a/test/utilities.jl b/test/utilities.jl index 8a2f5af..7f368b6 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -7,9 +7,9 @@ include("dummy.jl") # Allocating size for allocating a `BigInt`. Half size on 32-bit. -const BIGINT_ALLOC = let - sizeof(Int) + @allocated(BigInt(1)) -end +# v1.12.5 off by 8 +_big_int_alloc() = sizeof(Int) + @allocated(BigInt(1)) +const BIGINT_ALLOC = _big_int_alloc() @show BIGINT_ALLOC function alloc_test(f, n) From 9d79573aa7c9e65c6494e9a534eaa3e8ee7371df Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 15:36:07 +1300 Subject: [PATCH 07/12] Update --- test/big.jl | 4 ++-- test/matmul.jl | 8 ++++---- test/utilities.jl | 13 ++----------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/test/big.jl b/test/big.jl index 7c1b823..7205ea2 100644 --- a/test/big.jl +++ b/test/big.jl @@ -26,8 +26,8 @@ function allocation_test( A = MA.copy_if_mutable(a) @test A === short(A, b) @test g == A - alloc_test_le(() -> short(A, b), n) - alloc_test_le(() -> short_to(c, a, b), n) + alloc_test(() -> short(A, b), n) + alloc_test(() -> short_to(c, a, b), n) @test g == MA.buffered_operate!(nothing, op, MA.copy_if_mutable(a), b) @test g == MA.buffered_operate_to!(nothing, c, op, a, b) buffer = MA.buffer_for(op, typeof(a), typeof(b)) diff --git a/test/matmul.jl b/test/matmul.jl index 49ef20f..cdc33eb 100644 --- a/test/matmul.jl +++ b/test/matmul.jl @@ -204,7 +204,7 @@ end ) alloc_test(() -> MA.mutability(y, MA.add_mul, y, A, x), 0) end - + BIGINT_ALLOC = 2 * sizeof(Int) + _big_int_alloc() alloc_test(() -> MA.add_mul!!(y, A, x), BIGINT_ALLOC) alloc_test( () -> MA.operate_fallback!!(MA.IsMutable(), MA.add_mul, y, A, x), @@ -277,7 +277,7 @@ end ) alloc_test(() -> MA.mutability(C, MA.add_mul, C, A, B), 0) end - + BIGINT_ALLOC = 2 * sizeof(Int) + _big_int_alloc() alloc_test(() -> MA.add_mul!!(C, A, B), BIGINT_ALLOC) alloc_test(() -> MA.operate!!(MA.add_mul, C, A, B), BIGINT_ALLOC) alloc_test(() -> MA.operate!(MA.add_mul, C, A, B), BIGINT_ALLOC) @@ -473,8 +473,8 @@ function test_sparse_vector_sum(::Type{T}) where {T} y = copy(x) z = copy(y) # FIXME not sure what is allocating - alloc_test_le(() -> MA.operate!(+, y, z), 200) - alloc_test_le(() -> MA.operate!(-, y, z), 200) + alloc_test(() -> MA.operate!(+, y, z), 200) + alloc_test(() -> MA.operate!(-, y, z), 200) alloc_test(() -> MA.operate_to!(x, +, y, z), 0) alloc_test(() -> MA.operate_to!(x, -, y, z), 0) alloc_test(() -> MA.operate_to!(x, +, y), 0) diff --git a/test/utilities.jl b/test/utilities.jl index 7f368b6..c9ebff2 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -8,20 +8,11 @@ include("dummy.jl") # Allocating size for allocating a `BigInt`. Half size on 32-bit. # v1.12.5 off by 8 -_big_int_alloc() = sizeof(Int) + @allocated(BigInt(1)) -const BIGINT_ALLOC = _big_int_alloc() -@show BIGINT_ALLOC +_big_int_alloc() = @allocated(BigInt(1)) function alloc_test(f, n) f() # compile y = @allocated f() - @test n == y - return -end - -function alloc_test_le(f, n) - f() # compile - y = @allocated f() - @test n >= y + @test y <= n return end From 29c6d35dc3350c0d2dca70710703766f40f67c5e Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 15:43:53 +1300 Subject: [PATCH 08/12] Update --- test/dispatch.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/dispatch.jl b/test/dispatch.jl index 946405a..a7b4e34 100644 --- a/test/dispatch.jl +++ b/test/dispatch.jl @@ -15,12 +15,13 @@ function dispatch_tests(::Type{T}) where {T} c = one(T) x = convert.(T, [1, 2, 3]) # Need to allocate 1 BigInt for the result and one for the buffer - alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), 2BIGINT_ALLOC) - alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), 2BIGINT_ALLOC) + nalloc = 2 * (sizeof(Int) + _big_int_alloc()) + alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), nalloc) + alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), nalloc) if T <: MA.AbstractMutable - alloc_test(() -> x'x, 2BIGINT_ALLOC) - alloc_test(() -> transpose(x) * x, 2BIGINT_ALLOC) - alloc_test(() -> LinearAlgebra.dot(x, x), 2BIGINT_ALLOC) + alloc_test(() -> x'x, nalloc) + alloc_test(() -> transpose(x) * x, nalloc) + alloc_test(() -> LinearAlgebra.dot(x, x), nalloc) end end From ec6b333469f265e17ee7b76b801d03083b6a8975 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 16:55:02 +1300 Subject: [PATCH 09/12] Update --- test/dispatch.jl | 2 +- test/utilities.jl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dispatch.jl b/test/dispatch.jl index a7b4e34..e4d39ef 100644 --- a/test/dispatch.jl +++ b/test/dispatch.jl @@ -15,7 +15,7 @@ function dispatch_tests(::Type{T}) where {T} c = one(T) x = convert.(T, [1, 2, 3]) # Need to allocate 1 BigInt for the result and one for the buffer - nalloc = 2 * (sizeof(Int) + _big_int_alloc()) + nalloc = 3 * _big_int_alloc() alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), nalloc) alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), nalloc) if T <: MA.AbstractMutable diff --git a/test/utilities.jl b/test/utilities.jl index c9ebff2..3fd5524 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -10,9 +10,9 @@ include("dummy.jl") # v1.12.5 off by 8 _big_int_alloc() = @allocated(BigInt(1)) -function alloc_test(f, n) +function alloc_test(f, expected_upper_bound) f() # compile - y = @allocated f() - @test y <= n + measured_allocations = @allocated f() + @test measured_allocations <= expected_upper_bound return end From 3ea869547cec3ff7c1fa65eca47aa1a0a8453a25 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 17:14:13 +1300 Subject: [PATCH 10/12] Update --- test/rewrite_generic.jl | 8 +++----- test/utilities.jl | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/test/rewrite_generic.jl b/test/rewrite_generic.jl index e3a465c..9b86c07 100644 --- a/test/rewrite_generic.jl +++ b/test/rewrite_generic.jl @@ -480,20 +480,18 @@ function test_allocations_rewrite_unary_minus() MA.@rewrite(-sum(x[i] for i in 1:N), move_factors_into_sums = false) MA.@rewrite(sum(a * x[i] for i in 1:N), move_factors_into_sums = false) sum(-x[i] for i in 1:N) - total = @allocated sum(-x[i] for i in 1:N) - # actual value = @allocated( MA.@rewrite(sum(-x[i] for i in 1:N), move_factors_into_sums = false), ) - @test value < total + @test value < @allocated sum(-x[i] for i in 1:N) value = @allocated( MA.@rewrite(-sum(x[i] for i in 1:N), move_factors_into_sums = false), ) - @test value < total + @test value < @allocated -sum(x[i] for i in 1:N) value = @allocated( MA.@rewrite(sum(a * x[i] for i in 1:N), move_factors_into_sums = false), ) - @test value < total + @test value < @allocated sum(a * x[i] for i in 1:N) return end diff --git a/test/utilities.jl b/test/utilities.jl index 3fd5524..2331d3a 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -10,7 +10,7 @@ include("dummy.jl") # v1.12.5 off by 8 _big_int_alloc() = @allocated(BigInt(1)) -function alloc_test(f, expected_upper_bound) +function alloc_test(f::F, expected_upper_bound::Int) where {F<:Function} f() # compile measured_allocations = @allocated f() @test measured_allocations <= expected_upper_bound From 76ab035355f329a89c08a5cfb63ba80068f13249 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 31 Mar 2026 17:17:45 +1300 Subject: [PATCH 11/12] Update --- test/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utilities.jl b/test/utilities.jl index 2331d3a..73848de 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -10,7 +10,7 @@ include("dummy.jl") # v1.12.5 off by 8 _big_int_alloc() = @allocated(BigInt(1)) -function alloc_test(f::F, expected_upper_bound::Int) where {F<:Function} +function alloc_test(f::F, expected_upper_bound::Integer) where {F<:Function} f() # compile measured_allocations = @allocated f() @test measured_allocations <= expected_upper_bound From 57ba1f83a4d59870680177f93fcc821888b722a8 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 1 Apr 2026 08:05:23 +1300 Subject: [PATCH 12/12] Update --- test/dispatch.jl | 2 +- test/matmul.jl | 4 ++-- test/utilities.jl | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/test/dispatch.jl b/test/dispatch.jl index e4d39ef..272ea8c 100644 --- a/test/dispatch.jl +++ b/test/dispatch.jl @@ -15,7 +15,7 @@ function dispatch_tests(::Type{T}) where {T} c = one(T) x = convert.(T, [1, 2, 3]) # Need to allocate 1 BigInt for the result and one for the buffer - nalloc = 3 * _big_int_alloc() + nalloc = 3 * @allocated(BigInt(1)) alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), nalloc) alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), nalloc) if T <: MA.AbstractMutable diff --git a/test/matmul.jl b/test/matmul.jl index cdc33eb..9737dbf 100644 --- a/test/matmul.jl +++ b/test/matmul.jl @@ -204,7 +204,7 @@ end ) alloc_test(() -> MA.mutability(y, MA.add_mul, y, A, x), 0) end - BIGINT_ALLOC = 2 * sizeof(Int) + _big_int_alloc() + BIGINT_ALLOC = 2 * sizeof(Int) + @allocated(BigInt(1)) alloc_test(() -> MA.add_mul!!(y, A, x), BIGINT_ALLOC) alloc_test( () -> MA.operate_fallback!!(MA.IsMutable(), MA.add_mul, y, A, x), @@ -277,7 +277,7 @@ end ) alloc_test(() -> MA.mutability(C, MA.add_mul, C, A, B), 0) end - BIGINT_ALLOC = 2 * sizeof(Int) + _big_int_alloc() + BIGINT_ALLOC = 2 * sizeof(Int) + @allocated(BigInt(1)) alloc_test(() -> MA.add_mul!!(C, A, B), BIGINT_ALLOC) alloc_test(() -> MA.operate!!(MA.add_mul, C, A, B), BIGINT_ALLOC) alloc_test(() -> MA.operate!(MA.add_mul, C, A, B), BIGINT_ALLOC) diff --git a/test/utilities.jl b/test/utilities.jl index 73848de..93db66e 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -6,10 +6,6 @@ include("dummy.jl") -# Allocating size for allocating a `BigInt`. Half size on 32-bit. -# v1.12.5 off by 8 -_big_int_alloc() = @allocated(BigInt(1)) - function alloc_test(f::F, expected_upper_bound::Integer) where {F<:Function} f() # compile measured_allocations = @allocated f()