Skip to content

perf: accelerate triangular rational solves - #278

Merged
acgetchell merged 2 commits into
mainfrom
perf/246-triangular-solves
Oct 11, 2026
Merged

acgetchell merged 2 commits into
mainfrom
perf/246-triangular-solves

Conversation

@acgetchell

@acgetchell acgetchell commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

RationalMatrix::solve previously performed fraction-free elimination even when a row permutation made the system triangular. This adds structure recognition and direct exact substitution, reducing each solution component once. General and singular inputs retain the existing Bareiss path and typed singularity diagnostics. The public API, rational validation, and shared integer backend are unchanged.

Permanent benchmarks cover diagonal, upper/lower triangular, row-permuted triangular, sparse, and dense systems through D=8 with dyadic and non-dyadic coefficients. Regressions check exact residuals and independent Gaussian agreement through D=0–8, including arbitrary permutations, wide rationals, mixed signs, zero RHS, and singular inputs.

On the reproduced row-permuted triangular family, comparable Rust 1.99 measurements on an Apple M4 Max give:

D=8 operation Before After Speedup
Prepared solve 22.022 µs 1.975 µs 11.15×
Full runtime adapter 25.706 µs 6.041 µs 4.26×

The full adapter beats the captured legacy Gaussian reference at every size 2–8, with non-overlapping marginal 95% intervals. The dense Hilbert solve is effectively unchanged; the dyadic dense control increases 0.73% for prepared solves and 1.77% for the full adapter. These are synthetic fixture results, with no whole-triangulation performance claim.

The performance study retains all measurements, raw samples, commands, source hashes, and limitations. Both timing phases used the same baseline lockfile. This PR also includes the staged cc/syn lockfile refresh and uv/Ruff/Ty updates; those later updates were not part of the timing runs.

Validation: just ci passes on the final dependency set, including 1,002 Rust tests, 371 Python tests, default/exact doctests, Clippy, documentation, examples, and benchmark compilation. Markdown and spelling checks pass; retained source and measurement hashes were verified.

Closes #246

Summary by CodeRabbit

  • Performance
    • Exact rational solves for triangular systems now use direct substitution, including systems whose rows are permuted. Other systems continue to use the general solver.
  • Benchmarks
    • Added a benchmark suite comparing rational solve methods across matrix structures, coefficient types, and dimensions up to 8.
  • Documentation
    • Updated guides to explain rational solve behavior and benchmark coverage, and added a performance study of triangular rational solves.

- Recognize upper and lower triangular systems through row permutations
  and solve by exact substitution with one reduction per component.
- Preserve the general Bareiss path, canonical rational inputs, and typed
  singularity diagnostics without changing the public API.
- Add permanent structured benchmarks and retain Rust 1.99 measurements:
  11.15x faster prepared solves and 4.26x faster full adapters at D=8
  on the reproduced triangular family.
- Refresh the staged cc, syn, uv, Ruff, and Ty dependency/tooling pins.
- Validation: just ci passes, including 1,002 Rust tests, 371 Python
  tests, doctests, examples, and benchmark compilation.

Closes #246
@acgetchell acgetchell added this to the v0.4.7 milestone Oct 10, 2026
@acgetchell acgetchell added performance Performance related issues rust Pull requests that update rust code labels Oct 10, 2026
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: acgetchell/la-stack/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 13104e43-d991-4635-aaa3-66a5aedf7279


📥 Commits

Reviewing files that changed from the base of the PR and between 5921577 and fb25684.



📒 Files selected for processing (4)
  • CONTRIBUTING.md
  • benches/common/rational_solve.rs
  • docs/BENCHMARKING.md
  • docs/roadmap.md


🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/BENCHMARKING.md
  • benches/common/rational_solve.rs


Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.




📝 Walkthrough
📝 Walkthrough

Walkthrough

Rational matrix solving now uses exact substitution for recognized triangular systems, including row-permuted systems. Other systems retain the existing general solve path. The change adds regression tests, a rational-solve benchmark suite, and an archived performance study.

Changes

Rational solve optimization

Layer / File(s) Summary
Triangular recognition, substitution, and regression coverage
src/rational.rs, tests/rational_structured_solve.rs, REFERENCES.md, docs/mathematical_basis.md, docs/code_organization.md
The solver recognizes triangular ordering from distinct first or last nonzero columns and applies exact substitution. Unrecognized systems continue through the existing general path. Tests cover row permutations, fallback cases, exact results, and singularity metadata. Documentation describes the solve paths and test coverage.
Benchmark fixtures, execution, and validation
benches/common/rational_solve.rs, benches/rational_solve.rs, tests/exact_bench_config.rs, Cargo.toml, justfile, docs/BENCHMARKING.md, docs/code_organization.md
The fixtures build and validate structured rational systems. The Criterion suite measures legacy solving, construction, prepared solving, and adapter solving for dimensions 2–8. Benchmark compilation, configuration tests, and documentation include the suite.
Performance study and provenance
docs/archive/performance/studies/rational-triangular.md, docs/archive/performance/studies/rational-triangular.provenance.json, docs/archive/performance/studies/README.md, docs/code_organization.md
The archived study records measurements, controls, coverage, and limitations. The provenance record includes benchmark commands, correctness checks, and artifact metadata.

Repository tooling and release planning

Layer / File(s) Summary
Contributor tooling and roadmap updates
CONTRIBUTING.md, pyproject.toml, docs/roadmap.md
Contributor guidance describes shared Python development tooling and distinguishes contributor setup from Rust library use. Tool version pins change. The roadmap revises release sequencing and tracks expanded const-generics work separately.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant RationalMatrixSolve
  participant TriangularRecognition
  participant ExactSubstitution
  participant BareissBackend
  RationalMatrixSolve->>TriangularRecognition: Check row ordering by edge columns
  alt Triangular ordering recognized
    TriangularRecognition-->>RationalMatrixSolve: Return row map
    RationalMatrixSolve->>ExactSubstitution: Substitute using rational arithmetic
    ExactSubstitution-->>RationalMatrixSolve: Return canonical solution
  else Ordering not recognized
    TriangularRecognition-->>RationalMatrixSolve: Reject triangular path
    RationalMatrixSolve->>BareissBackend: Continue with general solve
    BareissBackend-->>RationalMatrixSolve: Return solution or singularity error
  end
Loading


Merge Risk: ⚪ Minimal · up to fb256

The optimization is limited to recognized triangular systems, and the recorded prerequisite chronology supports proceeding. No concrete merge-blocking risk remains.

Pre-merge checks | Passed 2 | Failed 1 | Inconclusive 1

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check Warning pyproject.toml and uv.lock upgrade uv, Ruff, and ty. These tooling changes do not implement the #246 solver, benchmarks, tests, or performance study. The PR description also states that the upda… Remove the uv, Ruff, and ty upgrades, their lockfile changes, and the unrelated roadmap edits from this PR. Move them to separate maintenance or release-planning changes. Keep only documentation that supports the #246 solver, tests, bench…
Linked Issues check Inconclusive Issue #246 implementation requirements are supported. RationalMatrix::solve recognizes row-permuted triangular systems, performs exact substitution, and retains the Bareiss fallback. The new benchma… Provide reviewable evidence that #251 was complete before the optimization work began and that the regression was reproduced under the completed Rust 1.99 / LLVM 23 baseline before implementation.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: improving performance for triangular rational solves.

Full details: Linked Issues check

Explanation

Issue #246 implementation requirements are supported. RationalMatrix::solve recognizes row-permuted triangular systems, performs exact substitution, and retains the Bareiss fallback. The new benchmarks separate construction, prepared solve, and adapter solve across the required structures and coefficient types. The regression tests cover exact residuals, independent Gaussian agreement, dimensions 0–8, permutations, wide rationals, mixed signs, zero RHS, fallback cases, and singularity metadata. The public API, rational validation, exact arithmetic, and shared Bareiss backend remain unchanged. The reported Rust 1.99 measurements support the required baseline and performance checks. The evidence does not establish that #251 was complete before optimization work began, as required by #246.


Full details: Out of Scope Changes check

Explanation

pyproject.toml and uv.lock upgrade uv, Ruff, and ty. These tooling changes do not implement the #246 solver, benchmarks, tests, or performance study. The PR description also states that the updates were not part of the timing runs. docs/roadmap.md adds broad v0.5.0 release planning for unrelated issues, release tooling, publication, and const generics. Those edits do not document the #246 implementation or its required evidence.

Resolution

Remove the uv, Ruff, and ty upgrades, their lockfile changes, and the unrelated roadmap edits from this PR. Move them to separate maintenance or release-planning changes. Keep only documentation that supports the #246 solver, tests, benchmarks, or performance study.


  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR





🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.14%. Comparing base (d12bdb4) to head (fb25684).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #278      +/-   ##
==========================================
+ Coverage   98.12%   98.14%   +0.01%     
==========================================
  Files          14       14              
  Lines        7112     7160      +48     
==========================================
+ Hits         6979     7027      +48     
  Misses        133      133              
Flag Coverage Δ
unittests 98.14% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 10, 2026
- Plan the stable-Rust v0.5.0 release sequence and conditional algebraic
  floating-point adoption, with compatible follow-up work in v0.5.1.
- Defer expanded const generics until the required Generic Const Arguments
  capabilities are stable.
- Clarify that research-repo-tools is a contributor development dependency.
- Describe dense benchmark controls as row-permuted while preserving
  measured inputs and retained performance evidence.

Refs #123, #246, #250
@acgetchell
acgetchell marked this pull request as ready for review October 11, 2026 00:28
@acgetchell
acgetchell enabled auto-merge October 11, 2026 00:28
@acgetchell
acgetchell merged commit 905aba7 into main Oct 11, 2026
22 checks passed
@acgetchell
acgetchell deleted the perf/246-triangular-solves branch October 11, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance related issues rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: avoid unnecessary exact elimination for triangular rational systems

1 participant