[Rd] request: allow inline functions in R

Li Long lilong at isb-sib.ch
Mon May 17 15:16:28 CEST 2004


> BTW, I've just checked a hunch. I did not believe R_IsNaNorNA is actually
> used in base R on a system with IEEE arithmetic (and I removed it to test
> that).  That suggests you have not actually tested inlining it and your
> analysis is seriously flawed.

R_IsNaNorNA is found in three dirs: main/arithmatic.c, nmath/mlutils.c,
nmath/nmath.h, include/R_ext/Arith.h and include/Rmath.h0.in.  (This is a
candidate for streamlining the codes. But that's a different subject. )

After I turned all of them inline, the model I have runs about 5% faster
on Itanium2 (running Linux).  When I cut down some calls in the package
(being developed) to ISNAN, the performance gain is another 5%. I
interprete this cost as quite significant.

>>
>> Could you then please quantify that hidden cost?

In package "cluster", pam.c and clara.c contain a function "ind_2" which
is used very heavily in the loop. After changing this function to be an
"inline" function, the model speeds up by factor of 2.  That's very
significant improvement for the model.  It also indicates the overhead
these small functions incur.

>> In what sense do `we' not allow it?  And who is `we'?

What I meant for "we" is "R core developers".  At this time, R adhers
strict C89 standard, so no inline function is allowed.

>> The problem is that very few compilers fully support C99, and others
>> have
>> different ways to indicate inlining.  So a configure test is needed. I
>> am
>> sure that if you provide one together with patches to parts of the code
>> where you find inlining beneficial, the real `we' would consider it
>> carefully.  Especially if the `hidden cost' is noticeable.

I'm not aware of other ways of indicating "inlining" by other compilers,
could you please give an example?

The request is to allowed "inline", not full C99 support.

As indicated in my original request, compiler could choose to treat
"inline" functions the same as normal functions. C++ supports "inline"
functions from the beginning, and C99 puts it in as a new keyword, "gcc"
supports it since 2.95, these point to a mature feature of the C language.

The inline functions are most suitable for small functions so that they
don't stall the pipeline, and they should be used when they are most
beneficial.  From this aspect, the portability and compatability issues
are easily manageable.

Li Long



More information about the R-devel mailing list