Profiling-driven fixes (2026-07-25) - #226
Merged
Merged
Conversation
…_hcat instead of generic hcat and avoids the SparseArrays dispatch
…n define_regions \n Replace element-by-element broadcast copyto! with face-by-face broadcast! for gcmarray/gcmvector
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #226 +/- ##
==========================================
+ Coverage 87.02% 87.50% +0.47%
==========================================
Files 37 37
Lines 3446 3538 +92
==========================================
+ Hits 2999 3096 +97
+ Misses 447 442 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…th a for loop, reusing xymsk(b) mask.
results to bypass CatView materialize! and its ~40-level recursion
…ce-level loops to eliminate per-call gcmarray allocations ; 2) replace gcmarray broadcast+findall pattern in define_regions with face-level loop, eliminating CatView nesting
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.
part 1
Fix A —
Polygons.jlSparseArrays wrong dispatch (done)to_Polygonsandto_LineStrings2Dused[a b c d e]syntax for 1×5 matrices.With contaminated upstream types this dispatched through SparseArrays (~1,093 samples, ~81% of
demo_gridruntime).Fix:
Float64[a b c d e]— forcestyped_hcat, plainMatrix{Float64}.Fix B — CatView deep nesting in
define_regions(done)Two sub-fixes:
src/types/gcmvector.jl—view(gcmarray, gcmvector): was buildingCatView(CatView(...))iteratively — O(nFaces) nesting, O(depth) cost per element write (~6,254 samples).Fix:
views = [view(A[a], B[a]) for a in eachindex(A)]; CatView(views...)— single-level flat CatView.src/Integration.jl—define_regionshot call sites:mask[findall(...)].=ldesugared todotview → view → CatView → broadcast.Fix: changed
.=lto=l— routes tosetindex!(gcmarray, Number, gcmvector)which does a direct face-by-face loop.Fix C — face-by-face broadcast
copyto!(done)Root cause:
A .* A,A .+ B, scalar broadcasts etc. all went through an element-by-elementgcmarray_getindex_evalfloop, allocating a new matrix per face per broadcast. Inconsistent with the fast face-by-face*,+,-,/methods inmain.jl.Fix in
src/types/gcmarray.jlandsrc/types/gcmvector.jl: rewrotecopyto!to loopfor I in CartesianIndices(dest.f)and callbroadcast!(bc.f, dest.f[I], face_args...). Helper_bc_facerewrites aBroadcastedtree by replacing eachAbstractMeshArrayarg with its face-Iinner matrix.Four bugs encountered and fixed during this rewrite:
gcmvector.similarleft innerArray{T,1}as undef references — fixed to allocate eachf[I]explicitly.eachindex(dest.f)returns linear integers for Julia Arrays;I[1]onIntis a no-op. Fixed toCartesianIndices(dest.f)soI[1]always gives the face dimension.GM_PsiX[:,k] .* DYG):_bc_facemust useI[1]for 1D sources and fullIfor 2D. Fix:ndims(a.f) == 1 ? a.f[I[1]] : a.f[I].exch_UVreplaces face matrices with larger halo-padded ones but does NOT updatefSize. Sosimilarallocates dest faces at wrong size →DimensionMismatch. Fix:copyto!recomputes result shape from actual face args viaBase.Broadcast.combine_axes, reallocatesdest.f[I]in-place if size mismatches.filter(a -> isa(a, AbstractArray), face_args)guards against scalar args which have noaxes.part 2
hoist xymsk(b) mask out of inner k-loop — zero Vector allocations per call
results to bypass CatView materialize! and its ~40-level recursion
part 3