Add pointer caching to reduce RHS callback allocations#515
Closed
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
Closed
Add pointer caching to reduce RHS callback allocations#515ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
Conversation
This PR reduces allocations in the RHS callback functions by caching array pointers and only creating new Julia array wrappers when the underlying pointer changes. Changes: - Add cached_u_ptr, cached_du_ptr, cached_resid_ptr fields to FunJac - Update cvodefunjac, cvodefunjac2, and idasolfun to use pointer caching - Add FunJac constructor for fun2 argument (ARKODE IMEX methods) - Fix callable struct syntax for Julia 1.12 compatibility - Update JET compat to support older versions The pointer caching optimization avoids creating new array wrappers on every function call when SUNDIALS reuses the same memory buffers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
This PR reduces allocations in the RHS callback functions by caching array pointers and only creating new Julia array wrappers when the underlying pointer changes.
cached_u_ptr,cached_du_ptr,cached_resid_ptrfields toFunJacstructcvodefunjac,cvodefunjac2, andidasolfunto use pointer cachingFunJacconstructor forfun2argument (ARKODE IMEX methods)The pointer caching optimization avoids creating new array wrappers on every function call when SUNDIALS reuses the same memory buffers. This should reduce GC pressure in tight integration loops.
Changes from PR #512
This PR is a cleaner implementation of the same optimization from #512, with:
Test plan
🤖 Generated with Claude Code