Skip to content

Add pointer caching to reduce RHS callback allocations#515

Closed
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:pointer-caching-optimization
Closed

Add pointer caching to reduce RHS callback allocations#515
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:pointer-caching-optimization

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

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.

  • Add cached_u_ptr, cached_du_ptr, cached_resid_ptr fields to FunJac struct
  • 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 (single-line format)
  • Update JET compat to support older versions for CI compatibility

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:

  • Julia 1.12 syntax compatibility (callable struct definitions rewritten to single-line format)
  • JET compat fix included

Test plan

  • All tests pass locally on Julia 1.10, 1.11
  • Package loads on Julia 1.12
  • CI passes on all Julia versions

🤖 Generated with Claude Code

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>
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.

3 participants