Native compilation of GNU Emacs byte-code
An attempt to speed up Emacs by translating byte-code functions to native code.
Every Elisp byte code can be compiled. Byte code functions are compiled at run-time, either before or after dumping of the Emacs binary. Arguments to the resulting native functions are handled like arguments to byte-code functions.
The GNU Lightning macros generate the native code.
The excursion was prompted by this
The CCL part has been solved by Unicode additions to Emacs. The native compilation additions presented here may be useful for investigating the rest (compilation of byte-code functions all the way to subrs), although the TODO entry has since been removed from the list.
Here is a Bzip Tar archive of the native compilation additions, on top of the Emacs CVS as at 1 June 2004. Many files (docs, change logs, .elc files...) have been left out to keep the archive small (12MB). The README.native file in the archive contains some introductory notes.
This (47KB) diff of the development tree may be an easier way to read the native compilation additions. It is a directory diff against the Emacs CVS as at 11 October 2004. Please ask if a more up-to-date diff, or any other help, is required.
Three speed comparisons follow. The commas in the middle column separate runs.
microseconds size in bytes copy-tree Byte 21, 21, 20, 21, 18 100 Native 28, 14, 14, 16, 17 2332 last Byte 15, 15, 16, 14, 15, 14 65 Native 12, 12, 12, 13, 19, 9 1605 native-test-info-eg-loop-small  Byte 187, 231, 233, 235, 235, 237, 485 13 Native 113, 158, 164, 172, 173, 186, 225 302
The resulting discussion with the Emacs developers is available in the emacs-devel archive.
A speedup over byte code is available, but in most cases it will be over-shadowed by the time spent in the primitive functions (the pre-compiled functions, which are written in C).
 This function, passed an N of 1000: (defun native-test-info-eg-small (n) "Loop N iterations." (while (> (setq n (1- n)) 0)))