"notjoin" joins are slow
@MarkusBonsch is already working on this.
Since Apr 14, 2018.
Assessment
This issue has not been assessed yet.
Description
Usually, joins using bmerge are expected to be faster than vector-based subsets. Therefore, normal subsets are replaced internally by joins for optimization. It turns out, however, that "notjoin" queries are slower as a join than as a simple subset. The reason is the expensive line:
i = irows = if (length(irows)) seq_len(nrow(x))[-irows] else NULL # NULL meaning all rows i.e. seq_len(nrow(x))
where a long vector is created via seq_len(nrow(x)):
## notjoin issue
## I added verbose messages for finding the issue
DT <- data.table(x = sample(1L:10L, 1e7L, replace = TRUE))
## switch off optimization. Otherwise, simple subset would be translated into a join
options(datatable.use.index = FALSE)
identical(DT[!x == 3L], DT[!data.table(x = 3L), on = "x"])
# [1] TRUE
system.time(DT[!x == 3L, verbose = TRUE])
# user system elapsed
# 0.020 0.000 0.018
system.time(DT[!data.table(x = 3L), on = "x", verbose = TRUE])
# Calculated ad hoc index in 0.06 secs
# Starting bmerge ...done in 0 secs
# Inverting irows for notjoin done in ... 0.23 sec
# user system elapsed
# 0.340 0.072 0.412
# Even with a proper key, the join is not faster
setkey(DT, x)
system.time(DT[!x == 3L, verbose = TRUE])
# user system elapsed
# 0.276 0.020 0.297
system.time(DT[!data.table(x = 3L, key = "x"), verbose = TRUE])
# Starting bmerge ...done in 0.001 secs
# Inverting irows for notjoin done in ... 0.216 sec
# user system elapsed
# 0.284 0.060 0.342
Therefore, it doesn't make sense to "optimize" notjoin queries towards bmerge until a fast implementation for the != operator exists in bmerge.
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·