On this page
Speed and memory optimization
Fine-mapping large genomic regions or thousands of molecular QTL loci with dense linkage disequilibrium (LD) matrices can be both compute- and memory-intensive. prusie accelerates SuSiE fitting and reduces peak memory usage by caching per-component matrix–vector products, exploiting exact column redundancy in finite-sample LD matrices, factoring invariant terms out of single-effect regression (SER) optimization, and avoiding redundant matrix allocations.
All optimizations operate in double precision (float64) and preserve the exact statistical model, priors, sequential IBSS update order, and stopping criteria of susieR (see Computational compatibility, Implementation, and Numerical accuracy). Across our empirical benchmarks on 200 FinnGen T2D GWAS loci and 14,157 GTEx whole-blood eQTL genes on exclusive AMD EPYC 7742 nodes, prusie achieved single-threaded runtime speedups of 42.9× in GWAS and 26.6× in eQTL (48.1× and 29.8× in the fitting stage) while reducing median peak memory by approximately fivefold.
Principles
prusie's optimizations reduce arithmetic and memory traffic without altering the statistical problem:
- No statistical approximations:
prusienever thresholds LD entries, prunes variants, or substitutes low-rank approximations. Grouping identical or sign-reversed LD columns accelerates matrix–vector multiplication while maintaining separate posterior probabilities for every variant. - Deterministic guards and fallbacks: Specialized execution paths (such as implicit scaling and exact signed-column grouping) check array layout, numerical bounds, and exact floating-point equality before activating, and fall back transparently to general
float64kernels whenever a precondition is not met. Activation of exact-column discovery is governed by deterministic operation counts rather than wall-clock timers. - Verified numerical consistency: Because regrouping floating-point additions or multiplications can introduce minor roundoff differences, every optimization is validated against
susieR0.16.6 across the completealphamatrix; see Computational compatibility and Numerical accuracy.
Where the time and memory go
For a region with variants, single-effect components, IBSS sweeps, and a candidate credible set of variants, the computational complexity and memory footprint of a standard dense Gaussian fit break down as follows:
| Stage | Time complexity | Array storage |
|---|---|---|
| Matrix validation and preparation | per matrix pass | per dense matrix; copies depend on layout and options |
| Component matrix–vector product | per update (ordinary dense kernel) | workspace plus retained component products |
| Single-effect regression (SER) | per posterior and prior-variance objective evaluation | scratch plus posterior arrays |
| Expected residual sum of squares (ER2) and ELBO | per sweep | scratch (reusing retained products) |
| Credible-set LD purity | pairwise evaluations | for sets passing the minimum-correlation check |
Over sweeps, dense matrix–vector products dominate runtime at operations, which exact signed-column classes can reduce substantially when perfect-LD redundancy is present. For individual-level data with samples, matrix products operate directly on the genotype matrix in time for dense storage or time for sparse storage using workspace; see Individual-level designs.
Fewer passes over the input matrix
Reusing the input array
With the default overwrite_ld=False, prusie preserves the caller's input matrix R or XtX. When the input is already an aligned, C-contiguous native float64 NumPy array that is symmetric, the Rust solver borrows its memory directly without copying (treating its transpose as a column-major view of the same buffer). Copies are allocated only when dtype conversion, memory-alignment repair, layout conversion, or symmetry repair is required; see Memory.
Combined validation
A single tiled traversal validates finiteness, nonnegative diagonal entries, and exact symmetry (, checked on when n is supplied or raw otherwise) without allocating a transpose temporary (see Shapes and numerical checks).
On x86-64 builds, a fast vectorized pre-check inspects contiguous LD matrices whose diagonal entries lie within of 1 and off-diagonal entries have magnitude at most . If the matrix is proved finite and exactly symmetric (with non-overflowing sample-size scaling), the solver proceeds directly without a second validation pass.
Fused validation and repair
If off-diagonal pairs and differ, prusie emits a RuntimeWarning and symmetrizes the working matrix as . For standard susie_rss fits (overwrite_ld=False, known n, var_y=None, and aligned C-contiguous float64 R), validation and repair are fused into a single pass whenever the fast symmetry proof does not apply: a private buffer is populated during traversal and kept only if an asymmetric pair is encountered (and freed immediately if the matrix turns out to be symmetric). For large matrices () with n_threads > 1, both the symmetry proof and owned repair can run in parallel across threads; see Threads.
When overwrite_ld=True is opted into, asymmetric entries are instead repaired in place inside the caller's R array without allocating a second buffer; see Optional LD workspace.
Implicit scaling
Let denote the validated (and, if needed, symmetrized) input matrix and contain the predictor standardization factors. The working Gram matrix is , where for unrepaired RSS matrices with known and otherwise. Rather than allocating a separate matrix to store , the solver evaluates matrix–vector products implicitly via two vector scalings:
This implicit path is enabled whenever , all and lie in , and all . If any parameter falls outside these bounds (or if an intermediate product produces a nonfinite value), prusie falls back to materializing the scaled matrix .
Matrix products in the sweep
Retained component products
Updating component in IBSS requires the residual crossproduct , where is component 's posterior mean vector. Whereas susieR caches only the total fitted crossproduct and recomputes matrix–vector products to remove and restore component contributions and evaluate the ELBO ( matrix–vector products per sweep), prusie retains each individual component product alongside their sum at a cost of only storage. Updating component then requires just one matrix–vector product ():
To illustrate with a two-variant, two-component example:
The products are and , giving . Component 1 uses residual (0.8, 0.4). Replacing its mean by changes the fitted crossproduct to (0.7, 0.8).
The cached products and are also reused at the end of each sweep to evaluate the expected residual sum of squares (; see Single-effect posteriors and effect means):
Because and are already cached, evaluating and the ELBO reduces from dense matrix–vector products to dot products (accumulated with compensated float64 summation), cutting the total quadratic work per IBSS sweep from matrix–vector products to .
Dense matrix–vector kernel
prusie's column-major dense matrix–vector kernel skips columns whose multiplier is zero and processes nonzero columns in groups of four to minimize load/store traffic on the output vector. On x86-64 processors, runtime feature detection selects an AVX2-accelerated kernel that preserves the exact per-column addition order of the portable scalar kernel. When n_threads > 1, large products partition output rows across threads; see Threads.
Exact signed-column classes
In finite reference panels, sets of variants in perfect positive or negative LD () produce identical or sign-reversed columns in the LD matrix. If the columns of the multiplied matrix ( under implicit scaling, or otherwise) partition into distinct exact signed-column equivalence classes, prusie sums the signed coefficients within each class (using compensated summation) and multiplies only the representative columns, reducing the product cost from to . When the corresponding row symmetries also hold exactly, a compact submatrix reduces the cost further to . Every variant retains its own separate coordinates in alpha, mu, and mu2.
To avoid paying the setup cost of class discovery on fits that converge in just a few sparse updates, activation is controlled by a deterministic work-count rule (activation.rs):
- A product is considered dense when at least entries of the multiplier vector are nonzero.
- On the first dense product, a fast 16-entry column hash estimates a lower bound on the class count . If this lower bound already exceeds , discovery is abandoned for the remainder of the fit.
- Otherwise, each subsequent dense product accumulates the estimated arithmetic savings of a grouped product over an ordinary product. Once the cumulative projected savings exceed the discovery cost, the solver runs full column verification—confirming every candidate match across all rows by exact
float64equality—and caches the grouping plan for all remaining sweeps.
Single-effect regression
During each component update with estimate_prior_variance=True and estimate_prior_method="optim", Brent's method evaluates the SER log marginal likelihood across multiple trial values of the prior variance , requiring operations per trial. prusie accelerates this inner optimization loop in four ways:
Grouped sampling variances
In the SER log Bayes factor formula, variants that share the same sampling variance (floored at float64 machine epsilon ) also share the log-determinant term and precision factor . Whenever a region has at most 16 distinct sampling variances—and in standard -score RSS with a unit-diagonal LD matrix, all informative variants share a single group—prusie evaluates the logarithm and division once per group rather than times per trial value of :
For , and marginal estimates , the common log term is -0.549306 and the denominator is 0.03. The log Bayes factors are (-0.515973, -0.415973, -0.249306).
Search invariants
Before launching Brent's search for component , the solver precomputes the invariant half-squared marginal estimates once across all variants. When prior weights are uniform (), the maximum of within each sampling-variance group directly identifies the maximum log weight required for the log-sum-exp shift, eliminating an pass on every Brent evaluation.
Vector exponentials
Evaluating the SER marginal likelihood and normalizing requires exponentiating shifted log weights . On GNU/Linux x86-64 builds (unless compiled with portable-math), prusie dispatches these exponentials to glibc libmvec (evaluating four float64 exponentials per AVX2 instruction or two per SSE2 instruction when standard IEEE-754 rounding and subnormal modes are active) and fuses the four-wide log-weight affine transformation.
Summation of likelihood weights
During prior-variance optimization, the nonnegative exponentiated weights are summed using an in-place balanced binary tree so that each term traverses at most additions, while final posterior normalization of and signed dot products in use compensated float64 summation.
Individual-level designs
For individual-level data (susie), prusie never forms the matrix . Instead, matrix–vector products are evaluated in two steps as
incorporating column centering (intercept=True) and standardization (standardize=True) on the fly via precomputed column means and scale factors. Dense genotype matrices cost time per product, compressed sparse column (CSC) matrices cost time, and 1D trend-filtering designs (susie_trendfilter of order ) use repeated cumulative sums in time, all using only working memory alongside the retained component products. Single-panel susie_rss(..., X=X) also uses this matrix-free design operator except on routes that require an explicit dense covariance matrix (see Supported model and input routes).
Memory
A single dense float64 matrix requires bytes:
At , bytes, or approximately 190.7 MiB.
When the caller passes a symmetric, aligned, C-contiguous float64 matrix R (or XtX) and implicit scaling applies, prusie operates directly on the caller's matrix without allocating any additional arrays—keeping the core solver's working memory at for alpha, mu, mu2, lbf_variable, and the retained component products .
Additional allocations occur only when needed for:
- coercing non-
float64, unaligned, or non-C-contiguous input arrays; - fused validation and repair (a temporary buffer is allocated during validation and retained only if the input matrix is asymmetric; in-place
overwrite_ld=Trueavoids this buffer when repairing asymmetric LD); - materializing when scale factors fall outside the implicit-scaling bounds, or when subsetting columns via
maf/ appending a physical null column on dense routes (design operators use a virtual zero-cost null column); - explicit matrix reconstruction on the
bhat/shat/var_yroute, dynamic RSS models (R_finite,R_mismatch, multi-panel RSS,susie_rss_lambda), or eigendecomposition whencheck_input=True; - storing a read-only input snapshot when input retention (
retain_data=True,track_fit,refine, or warm starts) is requested.
During credible-set purity evaluation on a candidate set of size , pairs are checked against min_abs_corr on the fly so that sets failing the threshold short-circuit immediately before allocating the array of pairwise correlations (needed only to compute the mean and median purity of retained sets).
Threads
Because IBSS updates components sequentially—each component depending on the residual left by the preceding component—prusie parallelizes work within each dense matrix–vector product and LD preparation step rather than across components.
When n_threads is set between 2 and 32 (default 1), prusie uses a private per-fit thread pool to partition output rows across workers for dense matrix products with at least rows and entries (using the reduced class count when a compact exact signed-column plan is active), while preserving deterministic within-row column summation order. Eligible susie_rss calls (, overwrite_ld=False) also parallelize the symmetry proof and fused validation/repair (see Native threading). Matrix-free design operators and Python dynamic RSS sweeps run serially with respect to n_threads.
Note that n_threads is configured per call (ignoring PRUSIE_NUM_THREADS) and never modifies global BLAS, OpenMP, or Rayon thread pools. In our thread-scaling benchmark across 87 real-data loci, 2 to 4 threads provided consistent speedups (0.799 and 0.735 median runtime ratios relative to 1 thread). When running many fine-mapping analyses in parallel across loci, running single-threaded (n_threads=1) with process-level parallelism across loci typically yields the highest overall throughput.
What prusie does not do
To summarize prusie's design boundaries:
- No heuristic LD pruning or thresholding: All optimizations preserve full double-precision (
float64) SuSiE inference; variant filtering viamafand extended likelihood options occur only when explicitly requested. - Numerical rather than bitwise equivalence with R: Because SIMD vectorization, retained-product updates, and grouped column operations reorder floating-point arithmetic relative to R/BLAS, results are validated by numerical agreement on the complete
alphamatrix rather than bitwise equality; see Computational compatibility and Numerical accuracy.