improve %chin% performance

Open
#5,334 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
performance

Research direction

Start with the discussion in pull request 5168 and locate the implementation of %chin% in the data.table source. Benchmark the current behavior for length-one and small inputs, including allocation of expressions such as c("one", "two"), then compare any change against the larger-input path; done means a measured performance improvement without regressions.

Written by the indexing model from the issue text.

Description

internals

Follow-up to https://github.com/Rdatatable/data.table/pull/5168#discussion_r807656380

const SEXP *td = STRING_PTR(PROTECT(coerceUtf8IfNeeded(table))) is always calling PROTECT even in the most common case that no coerce is needed. I don't know how much time PROTECT adds.

if (xlen==1) case is good for when length(x)==1. That could be extended to a double-loop for length(x)<=5, say, and only use the relatively heavier truelength approach for larger input.

Note that in data.table internals at R level where we use x %chin% c("one", "two") then that c("one","two") is an allocation and is probably happening on each call (it's possible the R compiler to byte code optimizes that but I'd be surprised if it does). So for decision making w.r.t. data.table internals (whether to use %chin% or ||), the benchmark needs to include the c("one","two")rather than timing %chin% in isolation, iiuc.

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.