Skip to content

Optimize summary stats mode: cache XtX*beta to eliminate 3x redundant…#132

Merged
xueweic merged 1 commit intomainfrom
optimize/cache-xtx-beta-phase1
Apr 1, 2026
Merged

Optimize summary stats mode: cache XtX*beta to eliminate 3x redundant…#132
xueweic merged 1 commit intomainfrom
optimize/cache-xtx-beta-phase1

Conversation

@gaow
Copy link
Copy Markdown
Contributor

@gaow gaow commented Mar 29, 2026

… O(P^2) computation

In summary statistics mode, XtX %*% beta was computed 3 separate times per iteration per outcome: in residual update, profile loglikelihood, and correlation update (get_correlation). This commit caches the product once after the beta update and reuses it, reducing the dominant O(P^2) cost by 3x.

Also precomputes per-outcome constants (scaling_factor, beta_scaling) during model initialization to avoid repeated conditional evaluation per iteration.

Benchmark results (micro-benchmark on XtX %*% beta):
P=1000, L=2, M=100: 0.43s -> 0.14s (3x speedup)
P=2000, L=5, M=200: 9.75s -> 3.25s (3x speedup)
P=5000, L=10, M=500: 324s -> 108s (3x speedup, saves 216s)

… O(P^2) computation

In summary statistics mode, XtX %*% beta was computed 3 separate times per
iteration per outcome: in residual update, profile loglikelihood, and
correlation update (get_correlation). This commit caches the product once
after the beta update and reuses it, reducing the dominant O(P^2) cost by 3x.

Also precomputes per-outcome constants (scaling_factor, beta_scaling) during
model initialization to avoid repeated conditional evaluation per iteration.

Benchmark results (micro-benchmark on XtX %*% beta):
  P=1000, L=2,  M=100:  0.43s -> 0.14s (3x speedup)
  P=2000, L=5,  M=200:  9.75s -> 3.25s (3x speedup)
  P=5000, L=10, M=500:  324s  -> 108s  (3x speedup, saves 216s)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.49%. Comparing base (2b5e1e1) to head (dac0997).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
R/colocboost_update.R 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
+ Coverage   84.05%   84.49%   +0.44%     
==========================================
  Files          14       14              
  Lines        4828     4837       +9     
==========================================
+ Hits         4058     4087      +29     
+ Misses        770      750      -20     

☔ View full report in Codecov by Sentry.
📢 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.

@xueweic xueweic merged commit d71bfcf into main Apr 1, 2026
7 checks passed
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.

2 participants