Skip to content

Commit 2929e93

Browse files
authored
Add type specialization for performance (#1)
1 parent 70b5214 commit 2929e93

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/neighborhood_search.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ struct PeriodicBox{NDIMS, ELTYPE}
99
end
1010
end
1111

12-
@inline function for_particle_neighbor(f, system_coords, neighbor_coords,
13-
neighborhood_search;
14-
particles = axes(system_coords, 2),
15-
parallel = true)
12+
# The type annotation is to make Julia specialize on the type of the function.
13+
# Otherwise, unspecialized code will cause a lot of allocations
14+
# and heavily impact performance.
15+
# See https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing
16+
function for_particle_neighbor(f::T, system_coords, neighbor_coords, neighborhood_search;
17+
particles = axes(system_coords, 2),
18+
parallel = true) where {T}
1619
for_particle_neighbor(f, system_coords, neighbor_coords, neighborhood_search, particles,
1720
Val(parallel))
1821
end

0 commit comments

Comments
 (0)