views:

76

answers:

2

How do I declare the types of the parameters in order to circumvent type checking?

How do I optimize the speed to tell the compiler to run the function as fast as possible like (optimize speed (safety 0))?

How do I make an inline function in Scheme?

How do I use an unboxed representation of a data object?

And finally are any of these important or necessary? Can I depend on my compiler to make these optimizations?

thanks, kunjaan.

+5  A: 
  1. You can't do any of these in any portable way.
  2. You can get a "sort of" inlining using macros, but it's almost always to try to do that. People who write Scheme (or any other language) compilers are usually much better than you in deciding when it is best to inline a function.
  3. You can't make values unboxed; some Scheme compilers will do that as an optimization, but not in any way that is visible (because it is an optimization -- so it should preserve the semantics).
  4. As for your last question, an answer is very subjective. Some people cannot sleep at night without knowing exactly how many CPU cycles some function uses. Some people don't care and are fine with trusting the compiler to optimize things reasonably well. At least at the stages where you're more of a student of the language and less of an implementor, it is better to stick to the latter group.
Eli Barzilay
+2  A: 

If you want to help out the compiler, consider reducing top level definitions where possible. If the compiler sees a function at top-level, it's very hard for it to guess how that function might be used or modified by the program. If a function is defined within the scope of a function that uses it, the compiler's job becomes much simpler.

There is a section about this in the Chez Scheme manual: http://www.scheme.com/csug7/use.html#./use:h4

Apparently Chez is one of the fastest Scheme implementations there is. If it needs this sort of "guidance" to make good optimizations, I suspect other implementations can't live without it either (or they just ignore it all together).

z5h