Skip to content

Prune contact pairs that can't touch; hardware sqrt on wasm - #23

Merged
ALopezMoreno merged 2 commits into
mainfrom
claude/project-thread-g4jisn
Oct 16, 2026
Merged

ALopezMoreno merged 2 commits into
mainfrom
claude/project-thread-g4jisn

Conversation

@ALopezMoreno

Copy link
Copy Markdown
Owner

Requested by Andres · project thread

Before: growing seed 11's bud took 15.1 s natively and 28.8 s under wasm. About two thirds of each energy evaluation went on contact pairs that weren't touching (about 1% of roughly 250k candidates were in contact).

After: the same bud takes 8.5 s natively and 11.8 s under wasm, and the output is byte-identical. Golden digests pass natively and under wasm (checked locally with the CI's sharded wasm run).

How:

  • Each contact candidate stores its distance from build time. While that distance, less how far its point and its triangle's corners have moved, is still at least dmin, the pair can't be in contact, so contacts() skips the closest-point test. It drops only pairs the test would discard, so the sums are unchanged.
  • candidates() bins nodes into a flat grid by counting sort, and scans each row's cells as one run, instead of using a hash map. The list is still sorted, so the grid affects speed only.
  • math::sqrt uses f64::sqrt. IEEE 754 requires sqrt to be correctly rounded, so the bits are the same everywhere. libm::sqrt already used the instruction natively but fell back to a software routine on wasm.
  • Docs: determinism.tex, packing.tex and core/PERFORMANCE.md are updated.

The opening's contact code (PR #14) can use the same skip. That is left to the flowering thread.

🤖 Generated with Claude Code

https://claude.ai/code/session_015vdZbN9NhQWL37K9Pfy1cE


Generated by Claude Code

Each bud contact candidate keeps its build-time distance and skips the
closest-point test while that distance, less how far its point and
triangle have moved, can't reach dmin. The candidate search bins nodes
into a flat grid instead of a hash map. math::sqrt uses the correctly
rounded hardware instruction, which libm only used natively.

Output is byte-identical: golden digests pass natively and under wasm.
Seed 11 bud: 15.1 s to 8.5 s natively, 28.8 s to 11.8 s under wasm.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015vdZbN9NhQWL37K9Pfy1cE
@ALopezMoreno ALopezMoreno self-assigned this Oct 16, 2026
ALopezMoreno pushed a commit that referenced this pull request Oct 16, 2026
Each pair keeps a lower bound on its distance at the anchors; energy skips
it while the bound minus the nodes' motion since still clears the contact
distance. Skin goes from 0.5 to 1.0 cap. Byte-identical output; seed 11
goes from 39 s to 35 s. Recipe from the Performance thread (#23).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015RyRGSRwEuGkCyT3Szodbz
@ALopezMoreno
ALopezMoreno merged commit 664fb63 into main Oct 16, 2026
6 checks 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.

2 participants