Skip to content

Avoid splatting in closures_to_opaque for faster Expr construction#116

Merged
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:cr/avoid-splatting-in-closures-to-opaque
Apr 8, 2026
Merged

Avoid splatting in closures_to_opaque for faster Expr construction#116
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:cr/avoid-splatting-in-closures-to-opaque

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

  • Replace Expr(head, array...) with Expr(head) + direct .args assignment in closures_to_opaque to avoid the overhead of splatting
  • This is the default/hot path in recursive AST traversal (line 378), hit for every Expr node that isn't a function def, generator, opaque_closure, or typed return
  • Also fixed splatting in the :generator branch (lines 362, 368)

Benchmark results

10,000 RGF creations of a moderately complex expression:

Time Allocations
Before (splatting) 0.768s 185.8 MB
After (no splatting) 0.623s 166.8 MB
Improvement ~19% faster ~10% less memory

The improvement compounds in downstream packages (e.g. ModelingToolkit) that create many RGFs during precompilation/build.

Test plan

  • Pkg.test() passes — all tests pass including Aqua

🤖 Generated with Claude Code

Replace `Expr(head, array...)` with direct `.args` assignment to avoid
the overhead of splatting. This is the hot path in recursive AST traversal
and reduces RGF creation time by ~19% and allocations by ~10%.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit a80df51 into SciML:master Apr 8, 2026
12 of 13 checks passed
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.

2 participants