You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using check_allocs on functions that involve FunctionWrappers.jl (as used by SciML's AutoSpecialize default in ODEProblem), the static analysis reports spurious allocation sites that do not correspond to actual runtime allocations. Switching to FullSpecialize (which avoids FunctionWrappers) eliminates all reported allocations.
AutoSpecialize wraps the user-provided ODE function in FunctionWrappers.jl to reduce compilation overhead. FunctionWrappers uses dynamic dispatch internally (via function pointers), which AllocCheck's static LLVM analysis cannot fully resolve. It flags the unresolvable call sites as potential allocations even though they don't allocate at runtime.
Context
This was discovered while fixing allocation tests in SciML/OrdinaryDiffEq.jl#3359. The workaround we adopted is to always use FullSpecialize in AllocCheck-based tests, but it would be helpful if this limitation were documented (or if check_allocs could detect/skip FunctionWrappers call sites).
Possible resolutions
Documentation: Add a note in the check_allocs / @check_allocs docs warning that FunctionWrappers-wrapped callables may produce false positives.
Detection: Optionally detect when a reported allocation site originates from inside FunctionWrappers.jl and warn the user rather than flagging it as an allocation.
Summary
When using
check_allocson functions that involveFunctionWrappers.jl(as used by SciML'sAutoSpecializedefault inODEProblem), the static analysis reports spurious allocation sites that do not correspond to actual runtime allocations. Switching toFullSpecialize(which avoids FunctionWrappers) eliminates all reported allocations.Minimum Working Example
Expected behavior
Both should report 0 allocations since
perform_step!does not allocate at runtime in either case. You can verify with@allocated:Root cause
AutoSpecializewraps the user-provided ODE function inFunctionWrappers.jlto reduce compilation overhead.FunctionWrappersuses dynamic dispatch internally (via function pointers), which AllocCheck's static LLVM analysis cannot fully resolve. It flags the unresolvable call sites as potential allocations even though they don't allocate at runtime.Context
This was discovered while fixing allocation tests in SciML/OrdinaryDiffEq.jl#3359. The workaround we adopted is to always use
FullSpecializein AllocCheck-based tests, but it would be helpful if this limitation were documented (or ifcheck_allocscould detect/skipFunctionWrapperscall sites).Possible resolutions
check_allocs/@check_allocsdocs warning thatFunctionWrappers-wrapped callables may produce false positives.FunctionWrappers.jland warn the user rather than flagging it as an allocation.