Repository navigation
Conversation
Instead of comparing both edge endpoints individually, build a 64-bit edge key and compare the entire key. This makes sure we have fewer unpredictable branches with cleaner codegen. The edge is built with the first vertex in the high bits; this does prevent the compiler from synthesizing a single 64-bit load, but this is for the best as this avoids load-store conflicts on the encoding path. This makes index encoding 5-10% faster depending on the mesh.
zeux
force-pushed
the
perftune
branch
2 times, most recently
from
October 6, 2026 23:14
bd49181 to
5a94c80
Compare
If the input contains outlier triangles with a significantly larger position vs others, this may skew the average towards the triangle and cause an early unbalanced KD node, which previously would consolidate it into a very large leaf. We now do this a bit more carefully: if the resulting count is still of an acceptable size, avoid splitting further, but otherwise keep splitting in hopes that we find a better axis after cutting the outliers out. The separate 0/count/depth checks help make sure that the process *always* terminates and produces a well-formed tree; effectively the first check is now required for convergence, and the second check is an efficiency heuristic.
computeBoundingSphere is used in 3-axis or 7-axis variant; previously, we used variable loop bounds and a single function. Using a compile-time loop bound allows the compiler to unroll the short loops and specialize the computations. This slightly increases code size, but makes computeSphereBounds ~25% faster; the effect on computeCluster/MeshletBounds is more muted but they too get up to 10% faster depending on the mesh.
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.
These changes collect fairly unrelated performance improvements; there's no central theme other than they were on the backlog that I'm in the process of cleaning out :)
meshopt_encodeIndexBuffer) is now 5-10% faster due to better codegenVertex encoding (meshopt_encodeVertexBuffer) is now 25-35% faster due to better codegen when using ClangMeshlet building (meshopt_buildMeshletsFlex) is now 4-8% faster due to a different variance estimatormeshopt_computeBoundingSphereis ~25% fasterETA: Eh, the new variance estimator is faster but a bit less numerically stable, and the overall gains did not warrant changing outputs and causing potential regressions in performance on poorly conditioned inputs so I removed that commit.
ETA(2): Ok, vertex encoding has more headroom that probably makes sense to claim at this point, but this makes this PR more complicated, so I will merge this as is and make a separate PR with just vertex encoding later :)
This contribution is sponsored by Valve.