perf(solve): reduce memory allocations in solve system hot paths#85
Merged
perf(solve): reduce memory allocations in solve system hot paths#85
Conversation
- Pre-allocate λ buffer and use in-place _build_stencil! with ldiv!/bunchkaufman! - Use view() for local_data instead of allocating new vectors - Replace polynomial evaluation allocation with dot() in Interpolator - Add copytri! for efficient symmetric matrix caching in forward_cache - Add _weight_view dispatch for Vector vs Matrix result slicing
5548b87 to
571e263
Compare
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
Contributor
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
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
forward_cache.jl: Pre-allocateA_fullandbworkspace outside the loop, reuse withfill!; replace[data[i] for i in neighbors]array comprehension withview(data, neighbors); replace manual lower-triangle copy withcopytri!; eliminate intermediatew = λ[1:k, :]sliceassembly.jl: Add in-place_build_stencil!(λ, A, b, ...)variant usingldiv!/bunchkaufman!to write solution into pre-allocated buffer and return aviewinstead of allocating a new array + sliceexecution.jl: Pre-allocateλsolve buffer alongsideAandbinweight_kernel; explicitly resetA_fullandbper stencil iteration; call new in-place_build_stencil!variantinterpolation.jl: Replace scalar accumulation loop withdot()for polynomial evaluation; add@inboundsto RBF accumulation loopCloses #73
Test plan
julia --project=. -e "using Pkg; Pkg.test()")_forward_with_cacheoutput format is preserved@benchmark update_weights!(lap)shows reduced allocationsInterpolatorevaluation shows reduced allocationsBenchmark results (10k points, 2D, PHS3 poly_deg=2)
update_weights!(Laplacian)mainInterpolator evaluation (500 pts)
maindot()+@inboundsimprove speed