Bug 16491 - 30-40% speedup for match(x,table) when x is of length 1
Summary: 30-40% speedup for match(x,table) when x is of length 1
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Low-level (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-07-28 04:40 UTC by Peter Haverty
Modified: 2015-12-14 13:48 UTC (History)
1 user (show)

See Also:


Attachments
patch (2.60 KB, patch)
2015-07-28 04:40 UTC, Peter Haverty
Details | Diff
timings and tests in vignette (15.08 KB, text/html)
2015-07-28 04:41 UTC, Peter Haverty
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Haverty 2015-07-28 04:40:22 UTC
Created attachment 1861 [details]
patch

The function 'match' is frequently used with an 'x' argument of length 1 to test for inclusion in a set. In particular, this pattern is common in the methods package. For cases like this, building a hash is unnecessary and faster/simpler options are available. This patch speeds up 'match' by 30-40% for the case of a scalar 'x'.

A bit of extra complexity is introduced in my current implementation to avoid the repeated calling of the SEXP data pointer macros. It may be better to simplify the code by calling the macros inside the loop as this imposes only a minor time penalty.
Comment 1 Peter Haverty 2015-07-28 04:41:18 UTC
Created attachment 1862 [details]
timings and tests in vignette
Comment 2 Martin Maechler 2015-09-17 14:39:46 UTC
Thank you.  I've changed it slightly to also "lookup"  COMPLEX() and RAW()..

In one of my test cases of  match(TRUE, <long-logical>)
this improved speed by more than a factor 10...  very impressively!

==>  In R-devel svn rev >= 69393