Skip to content

Builder: simplify 3-4 times faster, to the same meshes - #82

Merged
SamG-Coder merged 2 commits into
mainfrom
claude/builder-speed
Nov 12, 2026
Merged

SamG-Coder merged 2 commits into
mainfrom
claude/builder-speed

Conversation

@SamG-Coder

Copy link
Copy Markdown
Owner

What and why

The editor's phase 3 (woods and meadows baked in the browser) needs mesh building to be much faster, and the user asked for exactly that rather than a new file format of ready-made meshes. Profiling solstice-builder on one thread showed simplification taking 97% of a build. Within it, 90% went on one thing: each vertex's neighbours, UV seams, wedges and normal were worked out again, with allocation and sorting, for every one of the ~84 collapse costs that each collapse re-queues.

What changed in simplify.rs and dag.rs:

  • What is known around each vertex is kept. It is worked out again only when that vertex's triangles change: a per-vertex version, raised in collapse for from, to and every corner of every triangle that touched from.
  • Each edge is queued once. It used to be queued from both ends, which gave identical heap entries popped to the same effect.
  • A group simplified towards several targets is simplified once. Tree branches among twigs try 0.5, then 0.75, then 0.9. The collapses come in the same order whatever the target, so one run takes each result on the way down. Targets may come in any order.

The meshes built are the same, byte for byte. The old and new builders were compared by hashing:

  • the built meshes of oak, birch, bush and willow, wood and leaves;
  • a meadow patch;
  • a 256-cell terrain grid;
  • whole baked scenes, one with a wood and one with a meadow (identical SHA-256).

On one thread:

Mesh Before After
Terrain, 256 cells (131k triangles) 6.0 s 1.6 s
Oak's wood (95k) 1.78 s 0.47 s
Oak, wood and leaves (526k) 2.60 s 1.30 s
Birch 1.89 s 0.90 s

Leaves are thinned rather than simplified, so they were already fast. Willow's leaves (a million triangles) remain about 3 s, spread across welding and partitioning. Native bakes get the same speed-up, and so does the site's own build.

Verified

  • Local checks, run because CI may not run this month: bash scripts/check-changed.sh --all on this head (f15d1d6) passes. That covers fmt, clippy, 1,002 workspace tests including the GPU tests on the RTX 5080, the four wasm32 builds with clippy, and node apps/viewer/web/editor/test.mjs.
  • New test: a run to several targets gives exactly what separate runs give (sphere and seamed plane), with the targets given in any order.
  • New check in test builds: after every collapse, every kept neighbourhood the simplifier holds as current is checked against working it out afresh. All 79 builder tests pass with it, so no invalidation is missed in any of them.

Authorship

Written by: Claude Opus 5.5 through Claude Code

Reviewed by: Claude Sonnet 5.5. Nothing blocks merging. It verified:

  • the cache's invalidation is complete, including vertices of removed triangles and attributes changed by moved_corner;
  • the cached lists keep the old order, including the "first corner" normal;
  • the dropped heap entries were exact duplicates;
  • the snapshot semantics reproduce the old ratio loop, including equal targets and an early empty heap;
  • no RefCell path can panic.

Fixed from its points:

  • The several-target run assumed the targets descend, true only at the default ratio. They may now come in any order.

  • It suggested the check, in test builds, of every kept neighbourhood after each collapse. Added.

  • All code, text and comments in this pull request were written by a frontier AI model, with no human-written code, and will be reviewed by a frontier AI model before merging, as the Code of Conduct requires.

🤖 Generated with Claude Code

SamG-Coder and others added 2 commits November 13, 2026 10:10
Nearly all of a mesh's build is its simplification, and nearly all of that
was working out again, for each of the ~80 collapse costs a collapse
re-queues, each vertex's neighbours, UV seams, wedges and normal, each time
allocating and sorting. They are now kept per vertex and worked out again only
when its triangles change. Each edge is queued once rather than from both
ends, and a group simplified towards several targets, as a tree's branches
are, is simplified once, taking each result on the way down: the collapses
come in the same order whatever the target.

The meshes built are the same, byte for byte: oak, birch, bush and willow,
a meadow patch and a terrain grid, and whole scenes with woods and a meadow.
On one thread, a 256-cell terrain builds in 1.6 s rather than 6.0, an oak's
wood in 0.47 s rather than 1.78.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…urhood

From the review: several targets simplified in one run may now come in any
order, each result handed back in its place, so a target ratio above 0.75
can't quietly reorder the branch tries; and in tests, after every collapse,
each vertex's kept neighbourhood is checked against working it out afresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SamG-Coder
SamG-Coder merged commit c2a081b into main Nov 12, 2026
1 check passed
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