Performance improvements - #285
Open
barche wants to merge 3 commits into
Open
Conversation
ffreyer
reviewed
Sep 11, 2026
| normals_result = zeros(NormalType, length(vertices)) | ||
| for face in faces | ||
| v = vertices[face] | ||
| v = vertices[convert.(Int, face)] |
Collaborator
There was a problem hiding this comment.
Could this be fixed in a way where vertices[face] isn't an issue?
ffreyer
reviewed
Sep 11, 2026
Comment on lines
+472
to
+477
| function create_index(vertex, vertex_index_counter::Ref{Int})::T | ||
| vertex_index_counter[] += 1 | ||
| push!.(attribute_indices, vertex) | ||
| return convert(T,vertex_index_counter[] - 1) | ||
| end | ||
|
|
Collaborator
There was a problem hiding this comment.
Seems to be a leftover from a previous change
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.