Skip to content

computeCellDistance() OOM on Visium HD data: Rfast::Dist() allocates dense N×N matrix (>100K cells) #3

@gettygugu-dot

Description

@gettygugu-dot

computeCellDistance() in R/spatial.R (around line 556, SpatialCellChat v0.1.0) calls Rfast::Dist(coordinates) to compute a dense N×N pairwise distance matrix before thresholding it into a sparse matrix.

For high-resolution spatial data such as Visium HD 8µm bins, where N routinely exceeds 100K–400K cells, this dense matrix requires 244 GB (174K cells) to 1.6 TB (445K cells) of RAM, causing immediate OOM crashes on any standard machine.

Since the function ultimately only retains the small fraction of entries within interaction.range, the dense intermediate is unnecessary — a KD-tree nearest neighbor search (e.g., FNN::get.knnx) could construct the sparse distance matrix directly in O(N·K) memory (~0.2 GB), making SpatialCellChat feasible on Visium HD-scale datasets without downsampling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions