(lispref.info)Compilation Tips


Next: Documentation Tips Prev: Style Tips Up: Tips

Tips for Making Compiled Code Fast
==================================

   Here are ways of improving the execution speed of byte-compiled lisp
programs.

   * Use the `profile' library to profile your program.  See the file
     `profile.el' for instructions.

   * Use iteration rather than recursion whenever possible.  Function
     calls are slow in Emacs Lisp even when a compiled function is
     calling another compiled function.

   * Using the primitive list-searching functions `memq', `assq' or
     `assoc' is even faster than explicit iteration.  It may be worth
     rearranging a data structure so that one of these primitive search
     functions can be used.

   * Certain built-in functions are handled specially by the byte
     compiler avoiding the need for an ordinary function call.  It is a
     good idea to use these functions rather than alternatives.  To see
     whether a function is handled specially by the compiler, examine
     its `byte-compile' property.  If the property is non-`nil', then
     the function is handled specially.

     For example, the following input will show you that `aref' is
     compiled specially (Note: Array Functions.) while `elt' is not
     (Note: Sequence Functions.):

          (get 'aref 'byte-compile)
               => byte-compile-two-args

          (get 'elt 'byte-compile)
               => nil

   * If calling a small function accounts for a  substantial part of
     your program's running time, make the function inline.  This
     eliminates the function call overhead.  Since making a function
     inline reduces the flexibility of changing the program, don't do
     it unless it gives a noticeable speedup in something slow enough
     for users to care about the speed.  Note: Inline Functions.


automatically generated by info2www