Skip to content

nospecialize a few more things that gain many specializations without having significant runtime#4521

Open
KristofferC wants to merge 1 commit into
SciML:masterfrom
KristofferC:kc/nospecialize
Open

nospecialize a few more things that gain many specializations without having significant runtime#4521
KristofferC wants to merge 1 commit into
SciML:masterfrom
KristofferC:kc/nospecialize

Conversation

@KristofferC
Copy link
Copy Markdown

@KristofferC KristofferC commented May 11, 2026

I used SnoopCompile (JuliaDebug/SnoopCompile.jl#462 needed) to basically run https://juliadebug.github.io/SnoopCompile.jl/dev/tutorials/pgdsgui/ on creating an ODEProblem and looking at methods that had many specializations

  Top 30 methods by inclusive inference time
==================================================================================================================================
Rank  Method                                    Module                Inclusive(s)  Exclusive(s)  #Specs  Location
----------------------------------------------------------------------------------------------------------------------------------
   1  #get_A_b_from_LinearFunction#918          ModelingToolkitBase         1.8858        1.8352      89  /Users/kc/JuliaTests/SymbolicUtilPerf/ModelingToolkit.jl/lib/ModelingToolkitBase/src/problems/linearproblem.jl:125
   2  process_SciMLProblem                      ModelingToolkitBase         1.6369        0.0560      14  /Users/kc/JuliaTests/SymbolicUtilPerf/ModelingToolkit.jl/lib/ModelingToolkitBase/src/systems/problem_utils.jl:1511
   3  #_#795                                    ModelingToolkitBase         1.5327        0.0075       1  /Users/kc/JuliaTests/SymbolicUtilPerf/ModelingToolkit.jl/lib/ModelingToolkitBase/src/problems/odeproblem.jl:101
   4  ODEProblem                                ModelingToolkitBase         1.5317        0.0023       1  none:0
   5  #ODEProblem#793                           ModelingToolkitBase         1.5293        0.0008       2  none:0
   6  #_#794                                    ModelingToolkitBase         1.5276        0.0008       3  none:0
   7  ODEProblem                                ModelingToolkitBase         1.5273        0.0004       3  none:0
   8  ODEProblem                                ModelingToolkitBase         1.5264        0.0005       3  /Users/kc/JuliaTests/SymbolicUtilPerf/ModelingToolkit.jl/lib/ModelingToolkitBase/src/problems/odeproblem.jl:101
   9  #build_explicit_observed_function#699     ModelingToolkitBase         0.9100        0.5522      30  /Users/kc/JuliaTests/SymbolicUtilPerf/ModelingToolkit.jl/lib/ModelingToolkitBase/src/systems/codegen.jl:1219

This m method despecializes some of these and timing compile time and runtime for

using Multibody, ModelingToolkit

@named model = Multibody.Robot6DOF();
ssys = multibody(model)
prob = ODEProblem(ssys, [
                   ssys.mechanics.r1.phi => deg2rad(-60)
                   ssys.mechanics.r2.phi => deg2rad(20)
                   ssys.mechanics.r3.phi => deg2rad(90)
                   ssys.mechanics.r4.phi => deg2rad(0)
                   ssys.mechanics.r5.phi => deg2rad(-110)
                   ssys.mechanics.r6.phi => deg2rad(0)

                   ssys.axis1.motor.Jmotor.phi => deg2rad(-60) * (-105) # Multiply by gear ratio
                   ssys.axis2.motor.Jmotor.phi => deg2rad(20) * (210)
                   ssys.axis3.motor.Jmotor.phi => deg2rad(90) * (60)

                   ssys.axis1.motor.Jmotor.w => 0
                   ssys.axis2.motor.Jmotor.w => 0
                   ssys.axis3.motor.Jmotor.w => 0
               ], (0.0, 2.0));

I get for compile time and runtime respectively:


# PR:
# 20.132280 seconds (154.21 M allocations: 8.043 GiB, 7.63% gc time, 67.38% compilation time: 17% of which was recompilation)
# 5.196923 seconds (64.45 M allocations: 3.164 GiB, 14.40% gc time, 1.38% compilation time)

# Master:
#  23.805818 seconds (169.28 M allocations: 8.799 GiB, 8.30% gc time, 71.23% compilation time: 13% of which was recompilation)
#   5.201396 seconds (64.71 M allocations: 3.185 GiB, 15.22% gc time, 2.45% compilation time)

so no observed reduction in runtime but around 15% reduced compile time.

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.

1 participant