Issue #1612: benches/game: n-body counted against the fastest Rust entry

Open and answer this issue on GitHub.

performance, blocked · opened 2026-11-15 · updated 2026-11-18 · 4 comments

Part of #1611 (Benchmarks Game programs in benches/game/), which holds the method, the harness and the rules for findings. Built after the harness of #1611 (step 1), or together with it as the first program.

What it measures. Float arithmetic in a tight loop over a small fixed array of structs: the planets’ positions, velocities and masses, advanced step by step.

Starting point. examples/n-body/src/main.nika (169 lines) exists. Check first whether it is the Benchmarks Game algorithm with the same output; reuse it if so.

To build

  1. The Nikaia program in benches/game/n-body/, as a Nikaia programmer writes it first; a second version written for speed only if it differs.
  2. The fastest Rust entry for n-body from the Benchmarks Game, copied with its licence header and a link, as a binary of its own.
  3. Same output byte for byte at the chosen step count (the energy before and after, to 9 decimals).
  4. The rows in the table of #1611: instructions and mispredictions, overflow checks on and off, and tokens.
  5. Every row where Nikaia counts more: the cause from callgrind_annotate, filed as an issue.

Done when benches/game/game.sh prints n-body’s rows next to the Rust entry with the same output, and each loss names its issue.

Comments

keywan-ghadami, 2026-11-16

Brief queued: issue-1612


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #1612

Your work order is issue #1612, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/1612/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/performance/issue-1612.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.

Supervisor’s note (2026-11-16)


Generated by Claude Code

keywan-ghadami, 2026-11-16

Run: issue-1612, Result: partial: the loss’s issue number is not in the table yet (the driver files it from Found:); the rest of Done when holds

Tokens: input 72, cache read 2180588, cache write 77632, output 19858 Cost: 2.95 USD, time 6 min 28 s, turns 36

Report

Result: partial: the loss’s issue number is not in the table yet (the driver files it from Found:); the rest of Done when holds Files: benches/game/Cargo.toml benches/game/Cargo.lock benches/game/game.nika benches/game/n-body/rust-9.rs Commit: benches/game: n-body counted against the fastest Rust entry, harness game.nika Body: New benches/game/game.nika (run with nikaia run, a Nikaia program like benches/yaml/bench.nika; -- NAME runs one problem) holds the list of problems. For each it builds the Rust entry the way the game does (opt-level 3, one codegen unit, its target-cpu) and the Nikaia program at –cpu=x86-64 and x86-64-v3, each with overflow checks on and off. It checks that all of them print the same bytes, counts them with callgrind and prints the table with tokens. Rust #9 (the fastest Rust n-body, 2026-11-16) is copied unchanged into benches/game/n-body/rust-9.rs with its URL and licence link, built by benches/game/Cargo.toml (a workspace of its own). examples/n-body/src/main.nika is the game’s algorithm and prints the same, so it is reused, not copied. Per step at 1M steps, checks on/off: Rust #9 196.4/196.4 instructions; Nikaia x86-64 410.4/410.5 (2.09x); Nikaia v3 326.4/326.5 (1.66x); mispredicted 0.008 everywhere; tokens Rust 1768, Nikaia 1057. Output is -0.169075164 / -0.169086185 for all six binaries. Part: #1612, #1611 Pushed: local b063c560208805f8b514668de698e58a4b313556 Tests: built and ran NIKAIA=target/fast/nikaia nikaia run benches/game/game.nika twice: same output byte for byte, table above. nikaia check and fmt --check pass on game.nika. pre-push green with the files staged. No compiler change, so no fails-before run. Gate: green Deviation: the harness is game.nika, not game.sh (supervisor’s note, CLAUDE.md Helper tools). Item 1: no copy of the Nikaia program in benches/game/n-body/; the harness reads examples/n-body/src/main.nika (the issue: reuse it if it is the game’s algorithm). No second Nikaia version written for speed: the speed comes from float SIMD lanes, which Nikaia lacks (Found). #1611’s text was not in my prompt; the table’s columns follow benches/yaml. Found: n-body loses 1.66x in instructions (x86-64-v3) to Rust #9. Cause from callgrind_annotate and objdump: every count is in main, with no checks left (1 branch per step). Nikaia’s loop is LLVM’s 2-lane SLP with vsqrtpd and vdivsd per pair. Rust #9 computes the 10 pair distances 4 lanes wide (__m256d, vhaddpd) and replaces sqrt and division with vrsqrtps plus a Newton step. Nikaia cannot say this: std::simd has no floating-point lanes, which ADR-377 §4 leaves undecided, and std has no approximate rsqrt. Probe: let v: simd::Fixed[f64, 4] = simd::splat(1.0) is refused (f64 is no lane type, spec Part I §simd). Needs a decision on f64/f32 lanes with + - * / and sqrt/rsqrt. Needs: supervisor decision on floating-point lanes in std::simd (ADR-377 §4) for the n-body loss; the loss’s issue number then goes into the #1611 table Changelog: benches/game: n-body against the Benchmarks Game’s fastest Rust entry. nikaia run benches/game/game.nika counts n-body (examples/n-body) against Rust #9 with callgrind, overflow checks on and off: 1.66x the instructions at x86-64-v3, 2.09x at x86-64, at 60 % of the tokens. Issue: broke I3: the issue’s frame (#1611: the table’s columns, the harness) was not inlined, so the columns follow benches/yaml; wrong: names game.sh where CLAUDE.md wants Nikaia (the supervisor corrected it) Owner: none Friction: none Disk freed: removed benches/game/target (a stray cargo build); target/game-bench 5 MB kept for reruns; target/nikaia-project-tests not created in this run; disk 28G free Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDukWgopUzVU2M1TjK7

Debrief

  1. What cost the most: the two full harness runs (about 2 minutes each) and the slow nikaia build of the scratch project. I spent few turns; nothing went in circles.
  2. What I looked up:
    • #1611’s text (the table’s columns, the method): it wasn’t in my prompt, so I used benches/yaml/bench.nika as the pattern.
    • The game’s build flags and licence link, from its program page.
    • ADR-377 §4, which leaves float lanes undecided.
    • That --cpu takes only x86-64 levels, not ivybridge.
  3. Checks:
    • Run: check, fmt --check, the harness (twice), pre-push, and the simd probe.
    • Wasted: my first harness run. It printed the ratio ×100 and the wrong version line, so it had to run again.
    • Wasted: a stray cargo build inside benches/game left a target/ that I had to delete.
  4. Change that would have saved the most: inline the parent issue (#1611) whenever the brief says “build its frame together”. Its table and columns were the main thing I had to guess.
  5. What the issue lacked:
    • broke I3: #1611 (method, columns, rules for findings) was not inlined. It holds the frame the work depends on.
    • wrong: the issue names game.sh, but CLAUDE.md (Helper tools) wants Nikaia. The supervisor’s note corrected it.
    • rules-gap: the issue doesn’t say whether the Nikaia side should also be built at the Rust entry’s target-cpu. Nikaia’s --cpu can’t name ivybridge.
  6. Traps for the next builder:
Fact: Core nikaia build --cpu takes only x86-64, x86-64-v2, -v3, -v4 or native; to match a Rust entry built for target-cpu=ivybridge, use x86-64-v3, the least level that holds it.
Fact: Core std::simd has only integer lanes (ADR-377 D1, floats left open in §4), so simd::Fixed[f64, N] is refused; float-heavy benchmarks can’t match hand-written AVX Rust.
Fact: Core Running cargo build inside a bench crate that is its own workspace leaves a target/ in that directory; pass CARGO_TARGET_DIR under the repository’s target/.

Generated by Claude Code

keywan-ghadami, 2026-11-16

Driver: not queued, this issue waits for #1611, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-18

Driver: not queued, this issue waits for #1611, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

Back to Open Issues