From: Tel A.
Subject: Cmucl Compilation
Date: 
Message-ID: <1151081382.670904.282630@u72g2000cwu.googlegroups.com>
Hello everyone,

In a recent thread there was a post about how the cmu interpreter
generates lots of superfluous garbage which can be fixed by compiling
the function. This confused me for a bit because I was under the
impression that cmucl compiles -everything- regardless.

Sure enough (in cmucl 19c) ...

CL-USER> (defun delay (n) (dotimes (i n)))
DELAY
CL-USER> (compiled-function-p #'delay)
T

However, the demonstration in that thread still worked as explained...

CL-USER> (time (delay 10000))
; Compiling LAMBDA NIL:
; Compiling Top-Level Form:

; Evaluation took:
;   0.07 seconds of real time
;   0.056991 seconds of user run time
;   0.001 seconds of system run time
;   82,172,300 CPU cycles
;   0 page faults and
;   480,104 bytes consed.
;
NIL
CL-USER> (compile 'delay)
; Compiling LAMBDA (N):
; Compiling Top-Level Form:
DELAY
NIL
NIL
CL-USER> (time (delay 10000))
; Compiling LAMBDA NIL:
; Compiling Top-Level Form:

; Evaluation took:
;   0.0 seconds of real time
;   0.0 seconds of user run time
;   0.0 seconds of system run time
;   282,965 CPU cycles
;   0 page faults and
;   0 bytes consed.

So now that I've "compiled" an already compiled function, it runs
faster?

Now, from the looks of things, COMPILE reexamined the function and
optimized it, but now my question is what the interpreter was doing
when it compiled it. Why didn't it go ahead and optimize the function
as well? Is there a way to set it so that it will automatically
optimize the function definitions it gets? Am I just completely on the
wrong path?

Thanks!

From: ···············@yahoo.com
Subject: Re: Cmucl Compilation
Date: 
Message-ID: <1151099179.574276.8260@i40g2000cwc.googlegroups.com>
Here's the Hyperspec entry for compiled-function.  The answer to your
question is likely in the last sentence.  The entry for
compiled-function-p makes the same point.  (A CMUCL guru could tell us
what CMUCL is really doing.)

4.4.4

Any function may be considered by an implementation to be a a compiled
function if it contains no references to macros that must be expanded
at run time, and it contains no unresolved references to load time
values. See Section 3.2.2 Compilation Semantics.

Functions whose definitions appear lexically within a file that has
been compiled with compile-file and then loaded with load are of type
compiled-function. Functions produced by the compile function are of
type compiled-function. Other functions might also be of type
compiled-function.
From: Christophe Rhodes
Subject: Re: Cmucl Compilation
Date: 
Message-ID: <sqpsgz5vy1.fsf@cam.ac.uk>
···············@yahoo.com writes:

> Here's the Hyperspec entry for compiled-function.  The answer to your
> question is likely in the last sentence.  The entry for
> compiled-function-p makes the same point.  (A CMUCL guru could tell us
> what CMUCL is really doing.)

An interpreted function in CMUCL is in fact minimally compiled into
the first intermediate representation, a compiler data structure
essentially representing basic blocks of the function; when an
interpreted function is called, the system interprets this
representation (rather than the original source code).

Christophe