Skip to content

perf: use Matrix.gram() for XtX#28

Merged
lpatiny merged 1 commit into
mainfrom
perf/use-gram-for-xtx
Jun 23, 2026
Merged

perf: use Matrix.gram() for XtX#28
lpatiny merged 1 commit into
mainfrom
perf/use-gram-for-xtx

Conversation

@lpatiny

@lpatiny lpatiny commented Jun 23, 2026

Copy link
Copy Markdown
Member

Replace XtX = Xt.mmul(X) with X.gram() (new in ml-matrix 6.13.0) and bump ml-matrix to ^6.13.0. Bit-identical results; gram() skips zero entries, so on the 98.7%-sparse spectral fixture the XtX product (which dominated runtime) drops ~9×.

XtX = Xt.mmul(X) is the symmetric Gram matrix XᵀX. ml-matrix 6.13.0 adds
Matrix.gram() which computes only the upper triangle and skips zero
entries, so it is ~2x faster on dense inputs and far faster on sparse
ones. On the 98.7%-sparse spectral test fixture the full fcnnls run drops
from ~29.7 ms to ~3.2 ms per iteration (~9x), with bit-identical results.

Also bump ml-matrix to ^6.13.0 (required for gram()) and rework the
benchmark into a reproducible warmup + best-of-N harness.

Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lpatiny lpatiny force-pushed the perf/use-gram-for-xtx branch from 1b86891 to 8e2a244 Compare June 23, 2026 09:31
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.38%. Comparing base (64263da) to head (8e2a244).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #28   +/-   ##
=======================================
  Coverage   93.38%   93.38%           
=======================================
  Files          18       18           
  Lines         272      272           
  Branches       54       54           
=======================================
  Hits          254      254           
  Misses         15       15           
  Partials        3        3           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lpatiny lpatiny merged commit 36f1705 into main Jun 23, 2026
10 checks passed
@lpatiny lpatiny deleted the perf/use-gram-for-xtx branch June 23, 2026 09:39
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.

1 participant