Skip to content

perf: serial threshold in lifted build_next_layer - #1459

Closed
odinfree wants to merge 1 commit into
starkware-libs:devfrom
odinfree:perf-serial-threshold
Closed

odinfree wants to merge 1 commit into
starkware-libs:devfrom
odinfree:perf-serial-threshold

Conversation

@odinfree

Copy link
Copy Markdown

What

crates/stwo/src/prover/backend/simd/blake2s_lifted.rs, build_next_layer: use the serial chunk iterator below 2^10 nodes instead of dispatching rayon for the small fold layers. The pristine code dispatches par_chunks_mut down to single-node layers; Plonky3 uses the same 1024-node serial threshold.

The per-chunk work is refactored into a work closure shared by the parallel and serial arms; behavior is identical either way.

Why

  • Neutral on large-cache hosts (measured: 32.3 vs 32.4 ms medians on a 96-column lifted trace commit at log 20, Apple Silicon) — included for hosts where dispatch dominates the tiny folds.
  • Zero risk: output layers are bit-identical; committed roots unchanged.

Verification

  • cargo +nightly-2026-01-15 test -p stwo --release --features prover,parallel --lib: 267/267 pass (and with --features prover).
  • cargo +nightly-2026-01-15 clippy -p stwo --features prover,parallel -- -D warnings: clean (note: &closure trips needless_borrows_for_generic_args on this nightly — the closure is passed by value).
  • cargo fmt --check: clean.

Stacked after nothing — independent of #1458.

Below 2^10 nodes the rayon dispatch costs more than the fold itself;
use the serial chunk iterator there (Plonky3 uses the same 1024-node
threshold). Output is identical; neutral on large-cache hosts and helps
hosts where dispatch dominates the small fold layers.
@cursor

cursor Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Performance-only scheduling change with identical per-chunk hashing; existing CPU/SIMD parity tests cover Merkle roots.

Overview
build_next_layer in the SIMD lifted Blake2s Merkle path no longer always uses Rayon when the parallel feature is on. Layers with log_size below 10 (fewer than 1024 parent nodes) now fold with a serial chunks_mut loop; at log_size >= 10 it still uses par_chunks_mut, matching Plonky3’s 1024-node serial threshold.

The per-chunk SIMD Blake2 compress/transpose logic is unchanged but moved into a shared work closure invoked from either the parallel or serial iterator, so hashing output stays the same while avoiding Rayon overhead on tiny upper Merkle layers.

Reviewed by Cursor Bugbot for commit 6dd7dd2. Bugbot is set up for automated code reviews on this repo. Configure here.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.77%. Comparing base (826591c) to head (6dd7dd2).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1459   +/-   ##
=======================================
  Coverage   91.76%   91.77%           
=======================================
  Files         127      127           
  Lines       15173    15177    +4     
  Branches    15173    15177    +4     
=======================================
+ Hits        13924    13928    +4     
  Misses       1180     1180           
  Partials       69       69           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@odinfree

Copy link
Copy Markdown
Author

Withdrawing for the time being — the author needs to run an internal review before this is considered for submission. Will resubmit (or a maintainer can pick the idea up) after that review. Thanks for the CI run.

@odinfree odinfree closed this Sep 21, 2026
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.

3 participants