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

Jon Clayden jon.clayden at gmail.com
Wed Aug 12 15:57:10 CEST 2009

>    > 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  '=='

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

> 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.

Many thanks.


More information about the R-devel mailing list