From fb770644c4fa89ed3d803fbb62b6318820d89e6c Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Fri, 12 Dec 2025 23:36:21 +0200 Subject: [PATCH] refactor(domains): optimize update_geometry_cache! for zero-allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimize update_geometry_cache! to eliminate iterator allocations and update to use coords field. - Add @inline to update_geometry_cache! for better inlining - Change enumerate loop to indexed loop to avoid iterator allocation - Add @inbounds annotation for bounds-check elimination - Change ip.ξ to ip.coords to use new QuadraturePoint API --- src/domains/continuum/update_geometry_cache.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/domains/continuum/update_geometry_cache.jl b/src/domains/continuum/update_geometry_cache.jl index 9ae79b9..dd6a0fe 100644 --- a/src/domains/continuum/update_geometry_cache.jl +++ b/src/domains/continuum/update_geometry_cache.jl @@ -45,7 +45,7 @@ For each integration point: 3. Compute physical gradients ∇N = J^{-T} ⋅ ∇_ξ N 4. Store detJ * weight for integration """ -function update_geometry_cache!( +@inline function update_geometry_cache!( geometry_cache::GeometryCache, element_cache::ElementCache, kernel::AbstractKernel, @@ -61,7 +61,9 @@ function update_geometry_cache!( nnodes = length(conn) # Extract node coordinates (mesh.nodes already contains Vec{3}) - for (i, node) in enumerate(conn) + # Use indexed loop instead of enumerate to avoid iterator allocation + @inbounds for i in 1:nnodes + node = conn[i] geometry_cache.X[i] = mesh.nodes[node] end @@ -71,7 +73,7 @@ function update_geometry_cache!( @inbounds for ip_idx in 1:nips ip = ips[ip_idx] - ξ = ip.ξ + ξ = ip.coords # Reference gradients dN_dξ = get_basis_derivatives(element_cache.topology, element_cache.basis, ξ)