Slower `fsetdiff` vs `dplyr::setdiff`
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- r
- 领域
- performance
调研方向
Start by reproducing the issue's bench::mark comparison between data.table::fsetdiff and dplyr::setdiff using the supplied data.table inputs. Trace the fsetdiff implementation and compare the relevant work with the benchmarked alternative. Done means preserving fsetdiff's results while measurably reducing its runtime and memory allocation on this example.
由索引模型根据 Issue 内容生成。
描述
This came up after code profiling where a loop was calling fsetdiff in each pass among other things.
library(data.table)
olddt <- data.table::data.table(a = paste0(1:10000, "a"))
newdt <- data.table::data.table(a = paste0(1:10010, "a"))
bench::mark(DT = data.table::fsetdiff(newdt, olddt),
DPLYR = dplyr::setdiff(newdt, olddt),
min_iterations = 30,
relative = TRUE)[, 1:5]
# A tibble: 2 × 5
expression min median `itr/sec` mem_alloc
<bch:expr> <dbl> <dbl> <dbl> <dbl>
1 DT 10.7859 11.0259 1 1.81242
2 DPLYR 1 1 10.0019 1
bench::mark(DT = data.table::fsetdiff(newdt, olddt),
DPLYR = dplyr::setdiff(newdt, olddt),
min_iterations = 30,
relative = FALSE)[, 1:5]
# A tibble: 2 × 5
expression min median `itr/sec` mem_alloc
<bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt>
1 DT 4.77ms 5.66ms 171.193 763KB
2 DPLYR 432µs 505.4µs 1799.31 421KB
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.5.3 (2026-03-11 ucrt)
#> os Windows 11 x64 (build 26200)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United Kingdom.utf8
#> ctype English_United Kingdom.utf8
#> date 2026-06-07
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> bench 1.1.4 2025-01-16 [1] CRAN (R 4.5.2)
#> cli 3.6.6 2026-04-09 [1] CRAN (R 4.5.3)
#> data.table * 1.18.4 2026-05-06 [1] CRAN (R 4.5.3)
#> digest 0.6.39 2025-11-19 [1] CRAN (R 4.5.2)
#> dplyr 1.2.1 2026-04-03 [1] CRAN (R 4.5.3)
#> evaluate 1.0.5 2025-08-27 [1] CRAN (R 4.5.2)
#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.5.2)
#> fs 2.1.0 2026-04-18 [1] CRAN (R 4.5.3)
#> generics 0.1.4 2025-05-09 [1] CRAN (R 4.5.2)
#> glue 1.8.1 2026-04-17 [1] CRAN (R 4.5.3)
#> htmltools 0.5.9 2025-12-04 [1] CRAN (R 4.5.2)
#> knitr 1.51 2025-12-20 [1] CRAN (R 4.5.2)
#> lifecycle 1.0.5 2026-01-08 [1] CRAN (R 4.5.2)
#> magrittr 2.0.5 2026-04-04 [1] CRAN (R 4.5.3)
#> otel 0.2.0 2025-08-29 [1] CRAN (R 4.5.2)
#> pillar 1.11.1 2025-09-17 [1] CRAN (R 4.5.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.5.2)
#> profmem 0.7.0 2025-05-02 [1] CRAN (R 4.5.2)
#> R6 2.6.1 2025-02-15 [1] CRAN (R 4.5.2)
#> reprex 2.1.1 2024-07-06 [1] CRAN (R 4.5.2)
#> rlang 1.2.0 2026-04-06 [1] CRAN (R 4.5.3)
#> rmarkdown 2.31 2026-03-26 [1] CRAN (R 4.5.3)
#> rstudioapi 0.18.0 2026-01-16 [1] CRAN (R 4.5.2)
#> sessioninfo 1.2.4 2026-06-04 [1] CRAN (R 4.5.3)
#> tibble 3.3.1 2026-01-11 [1] CRAN (R 4.5.2)
#> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.5.2)
#> utf8 1.2.6 2025-06-08 [1] CRAN (R 4.5.2)
#> vctrs 0.7.3 2026-04-11 [1] CRAN (R 4.5.3)
#> withr 3.0.2 2024-10-28 [1] CRAN (R 4.5.2)
#> xfun 0.57 2026-03-20 [1] CRAN (R 4.5.3)
#> yaml 2.3.12 2025-12-10 [1] CRAN (R 4.5.2)
#>
#> [1] C:/Program Files/R/library
#> [3] C:/Program Files/R/R-4.5.3/library
#> * ── Packages attached to the search path.
#>
#> ──────────────────────────────────────────────────────────────────────────────
- 主要语言
- R
- 星标
- 3.9k
- 派生
- 1.1k
- 平均合并
- 8 分钟
- 30 天内合并 PR
- 2
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Rdatatable/data.table 的其他 Issue
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one)未关闭
难度 2/5 1-3 小时 新手友好度 88/100
Rdatatable/data.table#7887 ·
-
test() doesn't distinguish plain NA_real_, NaN可能已有人在做 @MichaelChirico 于 73 天前认领。 未关闭consistency tests
难度 2/5 1-3 小时 新手友好度 68/100
Rdatatable/data.table#7853 · 3 条评论 ·
-
HAVE_LONG_DOUBLE is conditioned on but never set可能已有人在做 @venom1204 于 517 天前认领。 未关闭internals
难度 2/5 1-3 小时 新手友好度 65/100
Rdatatable/data.table#6938 · 1 条评论 ·
-
encoding fread
难度 2/5 1-3 小时 新手友好度 65/100
Rdatatable/data.table#5179 · 8 条评论 ·
-
documentation programming
难度 2/5 1-3 小时 新手友好度 68/100
Rdatatable/data.table#3199 · 3 条评论 ·
查看 Rdatatable/data.table 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 65/100
-
Component: R
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
bug pixi-build-r
难度 2/5 1-3 小时 新手友好度 70/100
prefix-dev/pixi#7229 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 72/100
rstudio/reticulate#1933 ·