|
42 | 42 | #' @noRd |
43 | 43 | .compute_raster_chunk <- function(start_row, nrows, ncols) { |
44 | 44 | # Generate row/col indices for the chunk |
45 | | - rows <- rep(start_row:(start_row + nrows - 1), each = ncols) |
46 | | - cols <- rep(1:ncols, times = nrows) |
47 | | - |
48 | | - # Compute linear cell IDs (row-major order) |
49 | | - cell_ids <- (rows - 1) * ncols + cols |
| 45 | + # Generate continuous sequence of cell IDs directly (row-major order) |
| 46 | + # Optimization: Avoid allocating large row/col vectors |
| 47 | + start_id <- (start_row - 1) * ncols + 1 |
| 48 | + end_id <- start_id + (nrows * ncols) - 1 |
| 49 | + cell_ids <- start_id:end_id |
50 | 50 |
|
51 | 51 | list(values = as.integer(cell_ids), start = start_row, nrows = nrows) |
52 | 52 | } |
@@ -249,9 +249,11 @@ stream_raster_parallel_mirai <- function( |
249 | 249 | nrows_chunk <- chunk_def$nrows |
250 | 250 | ncols_chunk <- chunk_def$ncols |
251 | 251 |
|
252 | | - rows <- rep(start_row:(start_row + nrows_chunk - 1), each = ncols_chunk) |
253 | | - cols <- rep(1:ncols_chunk, times = nrows_chunk) |
254 | | - cell_ids <- (rows - 1) * ncols_chunk + cols |
| 252 | + # Generate continuous sequence of cell IDs directly (row-major order) |
| 253 | + # Optimization: Avoid allocating large row/col vectors |
| 254 | + start_id <- (start_row - 1) * ncols_chunk + 1 |
| 255 | + end_id <- start_id + (nrows_chunk * ncols_chunk) - 1 |
| 256 | + cell_ids <- start_id:end_id |
255 | 257 |
|
256 | 258 | list( |
257 | 259 | chunk_idx = chunk_idx, |
|
0 commit comments