Open jangorecki opened 8 months ago
And possibly many functions as well. whenever rev() is used we could cut its time to 1/2 or even 1/10 when it's safe to rev in place.
I turned the issue into more generic one. We could always save at least one allocation, of indices, and sometimes even of the results.
Noting a related r-devel bug to support ALTREP for rev():
We can use {lintr} to quickly identify usages inside the package (with more confidence over grep
since {lintr} is AST-aware):
lintr::lint_package(linters = lintr::undesirable_function_linter(c(rev = NA)))
R/as.data.table.R:37:9: style: [undesirable_function_linter] Function "rev" is undesirable.
val = rev(dimnames(provideDimnames(x)))
^~~
R/as.data.table.R:39:39: style: [undesirable_function_linter] Function "rev" is undesirable.
setattr(val, 'names', paste0("V", rev(seq_along(val))))
^~~
R/as.data.table.R:41:22: style: [undesirable_function_linter] Function "rev" is undesirable.
setcolorder(ans, c(rev(head(names(ans), -1L)), "N"))
^~~
R/as.data.table.R:102:9: style: [undesirable_function_linter] Function "rev" is undesirable.
val = rev(val)
^~~
R/as.data.table.R:104:39: style: [undesirable_function_linter] Function "rev" is undesirable.
setattr(val, 'names', paste0("V", rev(seq_along(val))))
^~~
R/as.data.table.R:106:93: style: [undesirable_function_linter] Function "rev" is undesirable.
stop("Argument 'value.name' should not overlap with column names in result: ", brackify(rev(names(val))))
^~~
R/as.data.table.R:112:10: style: [undesirable_function_linter] Function "rev" is undesirable.
dims = rev(head(names(ans), -1L))
^~~
R/bmerge.R:92:100: style: [undesirable_function_linter] Function "rev" is undesirable.
if (xclass=="integer64") { w=i; wc=ic; wclass=iclass; } else { w=x; wc=xc; wclass=xclass; nm=rev(nm) } # w is which to coerce
^~~
R/utils.R:43:27: style: [undesirable_function_linter] Function "rev" is undesirable.
length(x) - match(TRUE, rev(x)) + 1L
^~~
@anirban166 @DorisAmoakohene please investigate the memory savings using atime
_Originally posted by @ben-schwen in https://github.com/Rdatatable/data.table/pull/5441#discussion_r1443843574_