Skip to content
Prev 12638 / 63435 Next

request: allow inline functions in R

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.
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.
What I meant for "we" is "R core developers".  At this time, R adhers
strict C89 standard, so no inline function is allowed.
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