Closed lambdamoses closed 7 months ago
Right now the speedup would not work for GEOMETRY which has a mixture of different geometry types because st_coordinates
would not work. I'm waiting for official performance improvements in sf
itself as in https://github.com/r-spatial/sf/issues/2376
The code using the binary arithmetic operators on
sfc
is slow when the number of geometries is large, which is bad news when there're hundreds of thousands of cells:https://github.com/pachterlab/SpatialFeatureExperiment/blob/efed2e7c15a7949b9614c66a963d8e30a88d3f2c/R/geometry_operation.R#L627
From profiling, the slow part is the
mapply
called in thesf
package, which is essentially an R loop that is not parallelized:https://github.com/r-spatial/sf/blob/bd1940f68dd7607b7e9098ccc32c99e273c30a60/R/arith.R#L160
Try optimizing it by using
st_coordinates()
to get the coordinates, directly apply matrix multiplication for the linear transformation, and then usedf2sf()
(now using the really fastsfheaders
package behind the scene) to turn it back tosf
. Before going back tosf
, I wonder if thesweep()
step used to apply the translation is slow. I also wonder if this optimization issue should actually be opened in thesf
repo instead of here.