From maechler at stat.math.ethz.ch  Wed Aug 12 16:05:46 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 12 Aug 2009 16:05:46 +0200
Subject: [Rd] readBin() arg check has unnecessary overhead (patch
	included)
In-Reply-To: <68e086180908120657r47104be7l73f7ebb867143a8e@mail.gmail.com>
References: <68e086180908110951j2f684448jbb31707b8e02ad0f@mail.gmail.com>
	<19074.48183.102932.170100@lynne.math.ethz.ch>
	<68e086180908120657r47104be7l73f7ebb867143a8e@mail.gmail.com>
Message-ID: <19074.52282.467591.82824@lynne.math.ethz.ch>

>>>>> "JC" == Jon Clayden <jon.clayden at gmail.com>
>>>>>     on Wed, 12 Aug 2009 14:57:10 +0100 writes:

    >> ? ?> Dear all,
    >> ? ?> The version of readBin() in R-devel includes a use of match(), through
    >> ? ?> `%in%`, which can affect its performance significantly. By using
    >> ? ?> primitives instead of the rather expensive call to match(), I reduce
    >> ? ?> the time spent inside readBin() by more than 30% in some of my code
    >> ? ?> (part of the tractor.base package). A simple patch that does this is
    >> ? ?> given below. This passes "make check-devel" fine, and I don't see that
    >> ? ?> it could produce unexpected behaviour -- though I may, of course, be
    >> ? ?> wrong.
    >> 
    >> actually, ?%in% ?is liked by programmeRs for its inherent
    >> robustness combined with "expressiveness" (<-> readability)
    >> inspite of its potential efficiency loss wrt to ?'=='

    JC> Oh, absolutely. I like it and use it widely. But my feeling was that
    JC> in core code, a small loss in expressiveness for a significant
    JC> performance improvement is a trade worth making.

Yes, I agree, and hence the following ...

    >> and indeed, your patch fails in one case where the original code works:
    >> 
    >> ?readBin(., NA_character_, ...)
    >> 
    >> However that case can also be checked explicitly,
    >> and I will implement the corresponding patch.

now in R-devel, revision 49187.

    JC> Many thanks.
    JC> Regards,
    JC> Jon

Thank *you* ! {I forgot to say the first time ..}
Martin



[Rd] readBin() arg check has unnecessary overhead (patch included)
Martin Maechler