Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Compilation Speed

Name: Anonymous 2011-02-16 21:14

I have this code:
http://rghost.net/4410616

And it kills SBCL. But if I replace my-lst with

(defmacro my-lst (&rest xs)
  `(list ,@xs))

it compiles much faster.

Name: Anonymous 2011-02-17 7:29

>>5
vecs1 is just a simple vector of vector code generation function and it's trivial to compile and evaluate (it will just compile to an in-memory constant), on the other hand vecs2 invokes the compiler to do a much more complex job involving compiling multiple lambdas (functions in their own right), in which case over 400 functions in your second case, as opposed to just one in the first case. Of course having your compile compile 400+ functions will be slower than having it compile a single function (if at all).

EVAL is traditionally handled in two ways. Native-code compilers like SBCL (and others) will treat eval similar to
(defun eval (expression) (funcall (compile nil `(lambda () ,expression)))) (this is not 100% accurate as SBCL does do plenty of quick optimizations where possible, however such an implementation is usually the gist of it, if it encounters a lambda or something not trivially evaluatable). Which means that the interpreter is unneeded and can just be replaced to a call to the compiler. This is very wasteful in the second example, but not too wasteful in the first. (SBCL also has an interpreter, but I'm not sure how maintained or usable it is, I've never tried using it).

If you were to run EVAL in an implementation that just implements it metacircularily (such as how it's usually done in Scheme), or merely implementations which have full-fledged interpreters (CLISP and possibly AllegroCL have one), you would find that the second piece of code would be ran faster than it takes SBCL to compile it. I still do expect the second piece of code to run a bit slower, regardless of wether a real interpreter is used or not as it does involve more argument passing and setting up stack frames (function calling) as opposed to the first one.

tl;dr: Have a lot of random and complex code to execute at runtime that can't wait to run through a full-fledged compiler? Use an interpreter - either provided by the implementation or your own. If not? Enjoy your implementation provided eval which will most likely just compile your code first then run it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List