Fix spurious allocations in ret_allocs test helper on Julia 1.10/1.11#227
Merged
ChrisRackauckas merged 1 commit intoJul 12, 2026
Merged
Conversation
The "Non-allocating cache construction" testset asserts
ret_allocs(...) == 0, but the helper did not specialize on its `_f`
Function argument. Julia's default heuristic skips specialization for a
Function-typed argument that is only forwarded, so the inner
finite_difference_gradient! call dispatched dynamically and the wrapper
itself allocated ~48 bytes on Julia 1.10 and 1.11 (0 on 1.12+, where the
heuristic improved). This produced 12 `Evaluated: 48 == 0` failures on
the LTS while the library path is genuinely allocation-free (verified 0
bytes over 1000 direct calls).
Force specialization with `_f::F where {F}`; the full Core suite then
passes on Julia 1.11 (219 pass, 0 fail, 1 broken).
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
ChrisRackauckas
marked this pull request as ready for review
July 12, 2026 07:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The "Non-allocating cache construction" testset (
test/finitedifftests.jl) currently fails on Julia 1.10 and 1.11 with 12Evaluated: 48 == 0failures at:371/:379. It passes on Julia 1.12. This is a test-helper artifact, not a library regression — thefinite_difference_gradient!path is genuinely allocation-free.Root cause
Julia's default heuristic does not specialize a method on a
Function-typed argument that is only forwarded to an inner call. So_fis boxed insideret_allocs, the innerfinite_difference_gradient!becomes a dynamic dispatch, and the wrapper itself allocates ~48 bytes on 1.10/1.11 (0 on 1.12+, where the heuristic improved). The library work is 0 bytes.Independently verified the library allocates nothing:
@allocatedinside a function around the call =0Base.gc_bytes()=0totalProfile.Allocson a normally-compiled call =0allocationsFix
Force specialization on the function argument:
Verification
Ran the full Core suite locally on Julia 1.11:
FiniteDiff Standard Tests | 219 pass, 0 fail, 1 broken→Testing FiniteDiff tests passed(previously 207 pass / 12 fail / 1 broken).Please ignore until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code