Performance improvements - #285
Merged
Merged
Conversation
ffreyer
reviewed
Sep 11, 2026
ffreyer
reviewed
Sep 11, 2026
mateuszbaran
added a commit
to JuliaArrays/StaticArrays.jl
that referenced
this pull request
Sep 16, 2026
When indexing an array using a `StaticArray` as indices, the return type depends on the element type of the `StaticArray`, resulting in a slowdown when the type differs from `Int`, as seen in the normals calculation code in GeometryBasics.jl (see PR JuliaGeometry/GeometryBasics.jl#285). This change makes sure any kind of integer behaves the same way and always returns an `SVector` as the indexing result. --------- Co-authored-by: Mateusz Baran <mateuszbaran89@gmail.com>
Collaborator
|
I reverted the converts on faces again since the StaticArrays pr got merged. (Also checked that performance is still good). Tests here should fail though, since we have some checks for |
Collaborator
|
This can be merged now, right? |
Contributor
Author
|
All good, thanks for the updates! |
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.
This PR fixes an issue with a dynamic dispatch in the normals calculation and improves the performance of the
merge_vertex_indicesfunction. These problems were uncovered while working on PR JuliaGeometry/Meshes.jl#1405.merge_vertex_indicesI kept the two commits for the two steps in the improvement: one is a simple type instability fix, the other a rewrite of the algorithm to avoid relying on a
Dict.Performance was tested using:
Original code
Type stability fix (still using Dict)
Final version
Normals
The normals were tested using:
Original
Each time first
normalsand thenface_normals:After fix
Use of CodeGlass
These problems were tracked down using CodeGlass. For example, the

merge_vertex_indicescode showed the following allocation behavior:This indicated a problem converting from the
OffsetIndextype, and also an inability to infer the return type of the inlined function in theget!function applied to theDict.For the normals, all the points were dynamically allocated:

This indicated that the compiler could not infer the correct
getindexcall, and forcing the index type toIntfixed that.