performance of .I when subsetting rows from a global identifier

Open
#3,622 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data, performance

Research direction

Start with the reproducible R benchmark in the issue, comparing dd[,.SD[2], keyby = id], dd[,.SD[N], keyby = id], and the .I-based indexing expression. Investigate whether global identifier lookup accounts for the timing difference; done when the cause and expected performance behavior are established, with a regression check if a change is made.

Written by the indexing model from the issue text.

Description

GForce performance

This is related to this SO quesiton

set.seed(102938)

dd <- data.table(id = rep(1:10000, each = 10), seq = seq(1:10))
setkey(dd, id)

N <- 2
microbenchmark(dd[,.SD[2], keyby = id],
               dd[,.SD[N], keyby = id],
               times = 5)

The suggested approach was to use .I, though it improved the performance, it didn't match the performance of inserting the index value directly. Is it the search time for the identifier in the global env.

microbenchmark(dd[,.SD[2], keyby = id],
                dd[dd[,.I[N], keyby = id]$V1],
                times = 5)
Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.