Skip to content

Commit b8d6527

Browse files
authored
MA.operate!(+, pol1, pol2): prevent captured variable perf issue (#145)
The local function was spuriously recursive, making it not recursive fixes the performance problem. That is, this removes some run time dispatch and decreases the amount of allocation, but there's still some run time dispatch left in other places, according to JET.jl. Before: ```julia-repl julia> import MutableArithmetics; const MA = MutableArithmetics; julia> using DynamicPolynomials julia> @PolyVar x y; julia> p = 2x + y; julia> q = x + 2y; julia> @allocated MA.operate!(+, p, q) 34413936 ``` After: ```julia-repl julia> import MutableArithmetics; const MA = MutableArithmetics; julia> using DynamicPolynomials julia> @PolyVar x y; julia> p = 2x + y; julia> q = x + 2y; julia> @allocated MA.operate!(+, p, q) 30835632 ``` Both REPL runs was with nightly Julia v1.11.
1 parent 4c59103 commit b8d6527

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/operators.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ function MA.operate!(
154154
push!(p.a, t[1])
155155
return push!(p.x.Z, t[2])
156156
end
157-
compare_monomials(t::_NoVarTerm, j::Int) = _exponents_compare(q, j, t[2])
158-
compare_monomials(i::Int, j::Int) = compare_monomials(get1(i), j)
157+
compare_monomials_impl(t, j) = _exponents_compare(q, j, t[2])
158+
compare_monomials(t::_NoVarTerm, j::Int) = compare_monomials_impl(t, j)
159+
compare_monomials(i::Int, j::Int) = compare_monomials_impl(get1(i), j)
159160
combine(i::Int, j::Int) = p.a[i] = MA.operate!!(op, p.a[i], q.a[j])
160161
combine(t::_NoVarTerm, j::Int) = (MA.operate!!(op, t[1], q.a[j]), t[2])
161162
function resize(n)

0 commit comments

Comments
 (0)