Skip to content

Optimize Bivariate poly math#576

Open
dvdplm wants to merge 24 commits into
mainfrom
dvdplm/perf/bivariate-optimizations
Open

Optimize Bivariate poly math#576
dvdplm wants to merge 24 commits into
mainfrom
dvdplm/perf/bivariate-optimizations

Conversation

@dvdplm
Copy link
Copy Markdown
Contributor

@dvdplm dvdplm commented May 7, 2026

Refactor the BivariatePoly maths to avoid generic impl and instead provide only optimized code for the shapes in actual use: vector x matrix (partial_x_eval) and matrix x vector (partial_y_eval). These are now inlined (along with the vector x vector case).

Also in this PR:

  • smaller API (i.e. less pub methods)
  • infallible calls no longer return Result
  • a new partial_evals that compute both partial evals in one go (do note the TODO(dp) in the code though).

Note: In this PR the ndarray crate is still present and the generic matmul code is moved to matrix.rs. The follow-up PR #585 removes it entirely along with a second batch of optimizations that are unrelated to bivariate polys.

Added a few benchmarks and new tests.

This PR is ~3x faster than main on my machine for the deg 4 (i.e. 5x5 grid) case that we use in production.

group                                main                new
bivariate/evaluation/full/1          183.9±0.68ns        33.3±0.54ns    5.52x faster
bivariate/evaluation/full/4          496.5±2.57ns        147.1±4.11ns   3.37x faster <––
bivariate/evaluation/full/13         1897.6±5.13ns       999.5±4.04ns   1.90x faster

bivariate/evaluation/partial_x/1     110.5±0.65ns        23.3±0.54ns    4.73x faster
bivariate/evaluation/partial_x/4     350.1±1.08ns        118.5±7.40ns   2.95x faster <––
bivariate/evaluation/partial_x/13    1608.3±4.21ns       920.8±3.06ns   1.75x faster

bivariate/evaluation/partial_y/1     106.0±0.63ns        21.2±0.47ns    5.00x faster
bivariate/evaluation/partial_y/4     342.3±1.15ns        117.1±2.01ns   2.92x faster <––
bivariate/evaluation/partial_y/13    1574.0±7.88ns       899.2±3.62ns   1.75x faster

bivariate/from_secret/1              515.8±7.74ns        488.2±13.00ns  1.06x faster
bivariate/from_secret/4              4.0±0.03µs          3.9±0.14µs     1.03x faster
bivariate/from_secret/13             32.2±0.27µs         31.4±1.39µs    1.02x faster

@cla-bot cla-bot Bot added the cla-signed The CLA has been signed. label May 7, 2026
@dvdplm dvdplm self-assigned this May 7, 2026
@dvdplm dvdplm added the rust Pull requests that update rust code label May 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Consolidated Tests Results 2026-05-21 - 10:08:25

Test Results

passed 7 passed

Details

tests 7 tests
clock not captured
tool junit-to-ctrf
build build-and-test arrow-right test-reporter link #2318
pull-request Optimize Bivariate poly math link #576

test-reporter: Run #2318

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
7 7 0 0 0 0 0 not captured

🎉 All tests passed!

Tests

View All Tests
Test Name Status Flaky Duration
k8s_test_crs_uniqueness 43.9s
k8s_test_insecure_keygen_encrypt_and_public_decrypt 2m 13s
k8s_test_insecure_keygen_encrypt_multiple_types 2m 20s
k8s_test_keygen_and_crs 2m 10s
k8s_test_keygen_uniqueness 5m 19s
k8s_test_centralized_insecure 1m
nightly_full_gen_tests_default_k8s_centralized_sequential_crs 1.8s

🍂 No flaky tests in this run.

Github Test Reporter by CTRF 💚

🔄 This comment has been updated

dvdplm added 3 commits May 8, 2026 15:52
chore: moved compute_powers* to matrix
opt: do "outer Horner" for full_eval
opt: see if avoiding indexing is faster (avoids bounds checks)
@dvdplm dvdplm mentioned this pull request May 10, 2026
@dvdplm dvdplm marked this pull request as ready for review May 10, 2026 20:25
@dvdplm dvdplm requested a review from a team as a code owner May 10, 2026 20:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors bivariate polynomial evaluation to remove the prior generic/ndarray-driven evaluation path and replace it with specialized, inlined evaluation routines for the shapes used in production, while relocating the remaining generic matmul utilities into a new matrix module.

Changes:

  • Reimplemented BivariatePoly storage/evaluation to use a row-major coefficient Vec plus specialized partial_x_eval, partial_y_eval, full_eval, and fused partial_evals.
  • Moved generic MatrixMul + power precomputation helpers (compute_powers, compute_powers_list) into core/threshold-algebra/src/matrix.rs and updated imports/call sites.
  • Updated threshold execution VSS/PRSS code to use the new infallible bivariate APIs and introduced DoublePoly::from_bivariate to leverage fused partial evaluations.

Reviewed changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
dylint.toml Removes trailing formatting artifact in the config.
core/threshold-execution/src/small_execution/prss.rs Switches power-precompute + matmul imports to algebra::matrix.
core/threshold-execution/src/malicious_execution/large_execution/malicious_vss.rs Updates to infallible bivariate API and uses DoublePoly::from_bivariate.
core/threshold-execution/src/large_execution/vss.rs Updates evaluation calls to new bivariate API and adds DoublePoly::from_bivariate.
core/threshold-execution/src/large_execution/single_sharing.rs Replaces compute_powers usage with an inlined power-generation loop; updates matmul import.
core/threshold-execution/src/large_execution/double_sharing.rs Updates matmul import to algebra::matrix.
core/threshold-algebra/src/syndrome.rs Switches compute_powers_list import to matrix module.
core/threshold-algebra/src/matrix.rs New module containing MatrixMul + compute_powers* helpers and associated tests.
core/threshold-algebra/src/lib.rs Exposes the new matrix module.
core/threshold-algebra/src/galois_rings/degree_3.rs Switches compute_powers import to matrix module.
core/threshold-algebra/src/galois_rings/degree_4.rs Switches compute_powers import to matrix module.
core/threshold-algebra/src/galois_rings/degree_5.rs Switches compute_powers import to matrix module.
core/threshold-algebra/src/galois_rings/degree_6.rs Switches compute_powers import to matrix module.
core/threshold-algebra/src/galois_rings/degree_7.rs Switches compute_powers import to matrix module.
core/threshold-algebra/src/galois_rings/degree_8.rs Switches compute_powers import to matrix module.
core/threshold-algebra/src/galois_rings/common.rs Switches compute_powers_list import to matrix module.
core/threshold-algebra/src/bivariate.rs Replaces ndarray-based bivariate representation/eval with specialized vector-based routines and new tests.
core/threshold-algebra/Cargo.toml Adds Criterion dev-dependency and registers the new bivariate benchmark.
core/threshold-algebra/benches/bivariate.rs New Criterion benchmark suite for bivariate sampling/evaluation paths.
Cargo.lock Adds Criterion to the lockfile due to new benchmark dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/threshold-execution/src/large_execution/vss.rs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The CLA has been signed. rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants