Bug 16491

Summary: 30-40% speedup for match(x,table) when x is of length 1
Product: R Reporter: Peter Haverty <phaverty>
Component: Low-levelAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: enhancement CC: maechler
Priority: P5    
Version: R-devel (trunk)   
Hardware: All   
OS: All   
Attachments: patch
timings and tests in vignette

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