views:

113

answers:

3

What are some of the optimization steps that this command does

`(optimize speed (safety 0))`

Can I handcode some of these techniques in my Lisp/Scheme program?

+3  A: 
  1. What these things do in CL depends on the implementation. What usually happens is: there's a bunch of optimizations and other code transformations that can be applied on your code with various tradeoffs, and these declarations are used as a higher level specification that is translated to these individual transformations. Most implementations will also let you control the individual settings, but that won't be portable.
  2. In Scheme there is no such standard facility, even though some Schemes use a similar approach. The thing is that Scheme in general (ie, in the standard) avoids such "real world" issues. It is possible to use some optimization techniques here and there, but that depends on the implementation. For example, in PLT the first thing you should do is make sure your code is defined in a module -- this ensures that the compiler gets to do a bunch of optimizations like inlining and unfolding loops.
Eli Barzilay
You briefly mentioned "optimizations techniques here and there". Are there books or places where I can learn more about getting my program to be as efficient as possible?
kunjaan
@kunjaan: As Eli said, you should say more about precisely what lisp/scheme implementation you're using, because the advice will vary considerably.
khedron
kunjaan: also, there are of course many books on compilers and optimizations; they can be very different depending on the language that you're targeting and even the platform.
Eli Barzilay
+1  A: 

Higher speed settings will cause the compiler to work harder on constant folding, compile-time type-inference (hence eliminating runtime dynamic dispatches for generic operations) and other code analyses/transformations; lower safety will skip runtime type checks, array bound checks, etc. For more details, see Advanced Compiler Use and Efficiency Hints chapter of the CMUCL User's Manual, which applies to both CMUCL and SBCL(more or less).

huaiyuan
+1  A: 

I don't know, but I think the SBCL internals wiki might have some starting points if you want to explore.

Ken