"Inlining" (kind of) functions at runtime in C
Posted
by fortran
on Stack Overflow
See other posts from Stack Overflow
or by fortran
Published on 2010-05-05T17:33:15Z
Indexed on
2010/05/05
17:38 UTC
Read the original article
Hit count: 203
Hi,
I was thinking about a typical problem that is very JIT-able, but hard to approach with raw C. The scenario is setting up a series of function pointers that are going to be "composed" (as in maths function composition) once at runtime and then called lots and lots of times.
Doing it the obvious way involves many virtual calls, that are expensive, and if there are enough nested functions to fill the CPU branch prediction table completely, then the performance with drop considerably.
In a language like Lisp, I could probably process the code and substitute the "virtual" call by the actual contents of the functions and then call compile to have an optimized version, but that seems very hacky and error prone to do in C, and using C is a requirement for this problem ;-)
So, do you know if there's a standard, portable and safe way to achieve this in C?
Cheers
© Stack Overflow or respective owner