Skip to content

Assorted performance improvements - #1103

Merged
zeux merged 3 commits into
masterfrom
perftune
Oct 7, 2026
Merged

zeux merged 3 commits into
masterfrom
perftune

Conversation

@zeux

@zeux zeux commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

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 :)

  • Index encoding (meshopt_encodeIndexBuffer) is now 5-10% faster due to better codegen
  • Vertex encoding (meshopt_encodeVertexBuffer) is now 25-35% faster due to better codegen when using Clang
  • Meshlet building (meshopt_buildMeshletsFlex) is now 4-8% faster due to a different variance estimator
  • Cluster bound computations are now up to 10% faster; meshopt_computeBoundingSphere is ~25% faster

ETA: 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.

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
zeux force-pushed the perftune branch 2 times, most recently from bd49181 to 5a94c80 Compare October 6, 2026 23:14
zeux added 2 commits October 6, 2026 17:02
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.
@zeux
zeux merged commit c313aba into master Oct 7, 2026
13 checks passed
@zeux
zeux deleted the perftune branch October 7, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant