-
Notifications
You must be signed in to change notification settings - Fork 990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set automatically allocates new column slots if needed #5269
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5269 +/- ##
=======================================
Coverage 99.50% 99.51%
=======================================
Files 77 77
Lines 14660 14667 +7
=======================================
+ Hits 14588 14596 +8
+ Misses 72 71 -1
Continue to review full report at Codecov.
|
Looks good in that this solution works and it's a good issue to fix. Just wondering about any performance decrease, particularly when updating existing columns by name inside a loop. When |
Benchmark - Updating existing columnsSetupI used two different installations of R but both with version 4.1.1. And put everything into a script I call twice. First line is always the benchmark with an integer set, second one with a character set. Scriptlibrary(data.table)
# ensure that if branch hits
options(datatable.alloccol=1024L)
set.seed(373)
DT = as.data.table(matrix(rnorm(1e4*1e4), ncol=1e4))
cols = lapply(1:100, function(i) sample(ncol(DT), 2e3))
colsns = lapply(1:100, function(i) colnames(DT)[sample(ncol(DT), 2e3)])
R.home()
microbenchmark::microbenchmark(times=10,
for (i in cols) {set(DT, j=i, value=DT$V1)},
for (i in colsns) {set(DT, j=i, value=DT$V1)}
) 100 set / 2000 cols eachCurrent (
|
@mattdowle I tried to move everything down to the C level, hence, we save the 2nd What is still open is the question of whether we can also save the In case this is possible, we should change it also at |
R/data.table.R
Outdated
name = substitute(x) | ||
x = .Call(Cassign,x,i,j,NULL,value) | ||
if (is.name(name)) | ||
assign(as.character(name),x,parent.frame(),inherits=TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assign()
looks pretty complicated to reason about, I would like to see more tests of robustness here (setDT()
within a function, places where inherits=TRUE
is important, etc.).
At a glance I can't tell why this is needed though -- it definitely warrants a comment explaining why we need to branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified now the whole code. I also added a comment why we need the assign.
Ultimately it would be nice to let set
work also in the cases where it needs to overallocate and is inside a function, howeover, for making this to work we would need to find the right environment where to assign (might not be the first where x is present) and it is not clear whether it would be the last due to scoping
Generated via commit 26cdf8f Download link for the artifact containing the test results: ↓ atime-results.zip Time taken to finish the standard R installation steps: 3 minutes and 35 seconds Time taken to run |
Closes #1831
Closes #4100 (what's left is the duplicate of #496)
Towards #496 establishing consistent behavior between
set
and:=
Towards #678 closing
oldtncol = TRUELENGTH(dt); // TO DO: oldtncol can be just called tl now, as we won't realloc here any more.