Conversation
Don't overwrite list elements unless necessary. Also visit and adjust lists inside attributes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7820 +/- ##
=======================================
Coverage 99.01% 99.02%
=======================================
Files 88 88
Lines 17234 17250 +16
=======================================
+ Hits 17065 17081 +16
Misses 169 169 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Generated via commit cf6449a Download link for the artifact containing the test results: ↓ atime-results.zip
|
|
What immediately comes to my mind. How fast is this in terms of speed? |
| SEXP x; | ||
| int overAlloc; | ||
| }; | ||
| static SEXP realloc_nested_dt_list(SEXP x, int overAlloc, bool); |
There was a problem hiding this comment.
| static SEXP realloc_nested_dt_list(SEXP x, int overAlloc, bool); | |
| static SEXP realloc_nested_dt_list(SEXP x, int overAlloc, bool replacePairlists); |
or dont name arguments at all.
| x = list() | ||
| attr(x, 'dt') = data.table() | ||
| test(2379, truelength(attr(copy(x), 'dt')) > 0L) | ||
| rm(x) |
There was a problem hiding this comment.
should we add a test for nested tables?
inner = data.table(a=1)
DT = data.table(x=1:2, y=list(inner, inner))
DT2 = copy(DT)
test(2379.1, truelength(DT2$y[[1L]]) > 0L) # is FALSE in current master
test(2379.2, DT2$y[[1L]][, b := 2][, b], 2) # warns in current master
| # copy() reallocates data.tables inside list attributes, #7820 | ||
| x = list() | ||
| attr(x, 'dt') = data.table() | ||
| test(2379, truelength(attr(copy(x), 'dt')) > 0L) |
There was a problem hiding this comment.
what if we have multiple attributes like:
x = list()
attr(x, 'foo') = 1:2
attr(x, 'dt') = data.table()
truelength(attr(copy(x), 'dt'))|
Not sure how atime works internally, but could this be because of some C interface overhead? |
ben-schwen
left a comment
There was a problem hiding this comment.
Change LGTM. Might want to look deeper into timings before merging though

Rewrite
copy()in C so that instead of callingy[] <- lapply(y, reallocate)we can consider each individual list element and only callSET_VECTOR_ELTwhen necessary. This avoids the problem withxgboost's special altlist that must never be altered.Also walk the attributes of the object being copied, look for
data.tables and reallocate them. Maybe that's not necessary (copy()has been working fine without it) and can be taken out.Test 2224.3 points out an important detail: when
yis aLISTSXPpairlist,y[] <- lapply(y, reallocate)makes it into aVECSXPlist instead. It turns out we've been relying oncopy()automatically coercing pairlist columns into vector lists when constructingdata.tables. Should this become more explicit and be moved somewhere into thedata.table()constructor, leavingcopy()to just duplicate + reallocatedata.tables?Unfortunately this is hard to test without loading
xgboostor creating a different altclass.Fixes: #7456