Skip to content

Workaround slow inference for deletion - #3125

Closed
blegat wants to merge 1 commit into
masterfrom
bl/inferencebarrier
Closed

blegat wants to merge 1 commit into
masterfrom
bl/inferencebarrier

Conversation

@blegat

@blegat blegat commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

The problem with deletion is that we have 219 possible function/set VectorOfConstraints containers and even thought they are empty we still need to compile the methods for them to delete variables in their functions.

Julia Original first deletion With workaround
1.10.12 0.56 s 0.13 s
1.13.3 18.35 s 0.72 s
1.14.0-alpha2 16.66 s 0.33 s
1.15.0-DEV.244 16.49 s 0.34 s

There is a runtime tradeoff: with three tiny constraints, warmed deletion increased from 0.19 to 0.97 μs, allocating 432 additional bytes per deletion.

Closes #3124

@odow

odow commented Oct 29, 2026

Copy link
Copy Markdown
Member

The other option is

diff --git a/src/Utilities/struct_of_constraints.jl b/src/Utilities/struct_of_constraints.jl
index a376e2438..9f28b9d7b 100644
--- a/src/Utilities/struct_of_constraints.jl
+++ b/src/Utilities/struct_of_constraints.jl
@@ -33,12 +33,11 @@ function final_touch(model::StructOfConstraints, index_map)
 end
 
 function _throw_if_cannot_delete(model::StructOfConstraints, vis, fast_in_vis)
-    broadcastcall(model) do constrs
-        if constrs !== nothing
-            _throw_if_cannot_delete(constrs, vis, fast_in_vis)
-        end
-        return
+    function inner(@nospecialize constrs)
+        return _throw_if_cannot_delete(constrs, vis, fast_in_vis)
     end
+    inner(::Nothing) = nothing
+    broadcastcall(inner, model)
     return
 end
 
@@ -47,12 +46,11 @@ function _deleted_constraints(
     model::StructOfConstraints,
     vi,
 )
-    broadcastcall(model) do constrs
-        if constrs !== nothing
-            _deleted_constraints(callback, constrs, vi)
-        end
-        return
+    function inner(@nospecialize constrs)
+        return _deleted_constraints(callback, constrs, vi)
     end
+    inner(::Nothing) = nothing
+    broadcastcall(inner, model)
     return
 end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Deleting variables takes longer on Julia 1.13

2 participants