Skip to content

Commit f48fbf0

Browse files
committed
perf(epi_slide_opt.epi_archive): more [ -> vec_slice changes
14% or 17% time reduction for 7daving on a couple of test archives.
1 parent 5422363 commit f48fbf0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

R/epi_slide_opt_archive.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ epi_slide_opt_archive_one_epikey <- function(
8585
# Get additional values needed from inp_snapshot + perform any NA
8686
# tail-padding needed to make slider results a fixed window size rather than
8787
# adaptive at tails + perform any NA gap-filling needed:
88-
slide <- inp_snapshot[slide_inp_backrefs, ]
88+
slide <- vec_slice(inp_snapshot, slide_inp_backrefs)
8989
slide$time_value <- slide_time_values
9090
if (f_from_package == "data.table") {
9191
if (before == Inf) {
@@ -126,7 +126,7 @@ epi_slide_opt_archive_one_epikey <- function(
126126
# Only include time_values that appeared in the input snapshot:
127127
!is.na(slide_inp_backrefs)
128128
}
129-
out_update <- slide[rows_should_keep, ]
129+
out_update <- vec_slice(slide, rows_should_keep)
130130
out_diff <- tbl_diff2(prev_out_snapshot, out_update, "time_value", "update")
131131
prev_inp_snapshot <<- inp_snapshot
132132
prev_out_snapshot <<- tbl_patch(prev_out_snapshot, out_diff, "time_value")

R/patch.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ tbl_fast_anti_join <- function(x, y, ukey_names, val_names, abs_tol = 0) {
217217
xy_ukey_dup_ids <- vec_duplicate_id(xy_ukeys)
218218
xy_ukey_dup_inds2 <- which(xy_ukey_dup_ids != seq_along(xy_ukey_dup_ids))
219219
# ^ these should point to rows from y that had a ukey match in x
220-
xy_ukey_dup_inds1 <- xy_ukey_dup_ids[xy_ukey_dup_inds2]
220+
xy_ukey_dup_inds1 <- vec_slice(xy_ukey_dup_ids, xy_ukey_dup_inds2)
221221
# ^ these should point to the respectively corresponding rows from x
222222

223223
# Anything in `x` without a ukey match in `y` should be kept; start off with
@@ -371,7 +371,7 @@ tbl_patch <- function(snapshot, update, ukey_names) {
371371
# that we get the first appearance since `vec_duplicate_id()` guarantees that
372372
# it points to the first appearance.
373373
is_only_or_favored_appearance <- dup_ids == vec_seq_along(result_tbl)
374-
result_tbl <- result_tbl[is_only_or_favored_appearance, ]
374+
result_tbl <- vec_slice(result_tbl, is_only_or_favored_appearance)
375375

376376
result_tbl
377377
}

0 commit comments

Comments
 (0)