Performance: Zero-allocation colsupport using DisjointRange#42
Merged
ChrisRackauckas merged 2 commits intoJan 3, 2026
Merged
Conversation
Performance improvements: - Add DisjointRange type to represent the union of two ranges without heap allocation - Replace vcat in colsupport with DisjointRange, eliminating 6 allocations per call - colsupport now runs in ~6ns with 0 allocations (was ~145ns with 6 allocations) Testing: - Add allocation tests to verify key functions don't allocate - Tests cover DisjointRange, colsupport, rowsupport, getindex, setindex! - Tests run in "all" and "nopre" groups 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The fill! function should return the modified array per Julia conventions, not nothing. This allows chaining operations like `fill!(A, 0) |> f`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
Author
Performance Benchmark ResultsVerified the performance improvements translate to real matrix solves. colsupport Micro-benchmark (100x100 matrix, rank 5)
Full Matrix Solve (QR + ldiv!)
Summary
Remaining AllocationsThe ~20 allocations in the solve come from:
The triangular solve buffer could potentially be stack-allocated for small ranks using |
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
DisjointRangetype to represent the union of two non-overlapping ranges without heap allocationvcatincolsupportwithDisjointRange, eliminating 6 allocations per callBenchmarks
colsupport (for j > l+u)
Overall package performance
The package was already well-optimized. Key existing metrics:
Note: The ~1000 allocations in linear solve come from ArrayLayouts' handling of lazy
Multypes and are inherent to the current architecture (not easily fixable without architectural changes).Test plan
Changes
src/FastAlmostBandedMatrices.jl:DisjointRangetype with fullAbstractVectorinterfacecolsupportto useDisjointRangeinstead ofvcattest/alloc_tests.jl: New allocation test suitetest/Project.toml: Add AllocCheck and BenchmarkTools as test dependenciestest/runtests.jl: Include allocation tests in "all" and "nopre" groupscc @ChrisRackauckas
🤖 Generated with Claude Code