Performance: Fix allocation in p23_f! (Chandrasekhar function) - 76x speedup#173
Merged
ChrisRackauckas merged 1 commit intoSciML:masterfrom Dec 30, 2025
Conversation
…tests Performance improvements: - p23_f! (Chandrasekhar function): Eliminated allocation of temporary array by computing μ values inline. This provides: - 76x speedup (35.8μs → 470ns) - 0 allocations (down from 1008 allocations, 18KB) The fix replaces: - `μ = zeros(n)` with inline computation `μi = i/n` and `μj = j/n` - `out[1:n] = x[1:n]` with `@simd for` loop Added allocation tests using AllocCheck.jl to prevent regressions: - Tests p23_f!, p1_f!, and p2_f! for zero allocations - Tests run in the "nopre" group to avoid precompilation interference 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Merged
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
p23_f!(Chandrasekhar function) in NonlinearProblemLibraryPerformance Improvement
p23_f! (Chandrasekhar function)
Before:
After:
Speedup: 76x
Changes
Fix in
p23_f!The original code allocated a temporary array
μ = zeros(n)on every function call:The fix computes μ values inline since
μ[i] = (2*i)/(2*n) = i/n:Also replaced the allocating slice assignment
out[1:n] = x[1:n]with a SIMD loop.Allocation Tests
Added AllocCheck.jl tests to prevent regressions:
p23_f!,p1_f!, andp2_f!for zero allocationsTest Plan
cc @ChrisRackauckas
🤖 Generated with Claude Code