Inlining Routines

In some circumstances, euphoria may 'inline' the execution of a routine in certain places in a program. This means that instead of calling the routine as normal, equivalent code will be emitted in place of the call.

Advantages of Inlining

The code should run faster than equivalent non-inlined code.

  1. Euphoria is able to avoid the overhead of a routine call. This effect is greater for interpreted code than for translated code. This overhead includes setting up the call stack and initializing parameters and temporary variables for the routine. When the code is inlined, some of the parameters may not need to be copied to a temporary variable, nor dereffed when the routine returns.
  2. Potentially more information is available to euphoria regarding type information. When interpreted, the parser must always type check the passed parameters, for instance. When the routine is inlined, however, if it is a literal or constant value known at run-time, some of these checks can be omitted at run time. The translator can see even greater improvements. It tracks potential values when a routine is called. Since the code is generated for each call, the emitted C code can be much more tailored to the situation.

These advantages will be much more noticeable in code that is executed many times.

Disadvantages of Inlining

  1. The current design does not permit tracing into inlined routines, nor reporting the values of private variables in case of a run-time error. If these are needed, the problem code can be prevented from inlining by putting with trace before it.
  2. Translated code that is inlined will result in larger translated routines, which can increase compile time.

When will routines be inlined?

For a routine to be inlined, it must meet several criteria:

  1. It's IL code must be short enough (note that the exact size has not been determined, and it may be configurable)
  2. It must not have recursive calls that cannot be optimized as tail calls.
  3. with trace must not be in effect when the routine is defined.

If the routine has any forward references, the decision about whether or not it can be inlined will be deferred until all forward references have been resolved. At that point, any deferred routine will be evaluated, and then inserted into any routine or place in the top level code that called the routine.

Controlling inline behavior

Programs can use with/without inline [size] to affect the inlining of routines:

  • with inline This is the default setting. Using this will return parsing to the default size (currently 30, but this may change).
  • with inline size Allow inlining with a default routine size, where size is an integer.
  • without inline Any routines parsed while without inline is in effect will never be inlined into another routine.

Note that the inline directive will only change the routines eligible for inlining. It does not stop any inlining into routines.


Quick Links

User menu

Not signed in.

Misc Menu