unj2
unj2

Reputation: 53531

What are the things that optimize speed declaration do in CL?

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?

Upvotes: 1

Views: 218

Answers (3)

huaiyuan
huaiyuan

Reputation: 26539

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).

Upvotes: 1

Ken
Ken

Reputation: 5581

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

Upvotes: 1

Eli Barzilay
Eli Barzilay

Reputation: 29556

  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.

Upvotes: 3

Related Questions