Hi all,
I've sent in a bugzilla patch for an alternative C algorithm for
`which()` which uses less memory and is often faster in many real life
scenarios. I've documented it in full on the bugzilla page, with many
examples:
https://bugs.r-project.org/show_bug.cgi?id=18495
The short version is that the performance comes from making the loops
branchless, which seems to be particularly helpful for `which()`. With
`which(x)`, I'd argue that branches are often hard for the compiler to
predict since in most real data there is typically no indication that
if the i-th element of `x` is `TRUE`, then the i+1-th element might
also be `TRUE`.
I've received a few comments on the bugzilla page, but I'd love it if
anyone else could chime in and provide their own thoughts!
Thanks,
Davis Vaughan