[Larceny-users] turning on optimizations

William D Clinger will at ccs.neu.edu
Mon Mar 16 10:32:43 EDT 2009


Marijn wrote:
> Do you really mean init-sample here?

My mistake!  I was confused by a defect in the profiler.
My transformation of your code (to mimic block compilation)
turned your entire program into an anonymous closure, which
(being nameless) would never show up in the profiler!  The
loop1 I was seeing in the profile was not the loop1 in your
code (after my renaming of loops), but a loop1 in Larceny,
probably in the REPL.

I'll look at the execution profile for your program some
more after I fix the profiler to be less confusing.

> I was wondering about that. I recently changed all the global
> constants to functions in an attempt to help the compiler
> recognize that these things are just constants.

Compilers are more likely to recognize them as constants if
they're constants.

> In C these would be macros, in C++ constant variables, but I
> don't know what the best way is to express the same thing in
> Scheme.

I think it's okay to use macros for this, but your reliance
on constant-folding was okay too.

The problem is that not all Scheme compilers fold constants.
In particular, Twobit (Larceny's compiler) folds some constants
(e.g. sums and differences of small exact integers) but is very
conservative about constant folding because Twobit is often used
as a cross-compiler, where the host system may be something other
than Larceny.  Some host systems may not support bignums, or may
use floating-point precisions other than IEEE double.  To avoid
those problems, Twobit never folds operations that involve
inexact constants, and never folds operations whose results
might be bignums.  That's why Twobit never performs constant
folding for exp.  Twobit probably should fold (expt 40 2), but
expt is not currently one of the operations that Twobit folds,
mainly because expt is likely to involve bignums, non-integral
rationals, floating point, or non-real numbers.

> What is the best way to do that? Macros, force/delay, some other method,
> explicit set! maybe?

I'd suggest you define procedures that compute the values of
computed constants from the input parameters, and use those
procedures to define constants.  The rest of your program
would then use those defined constants instead of the procedures
that computed them.

Will



More information about the Larceny-users mailing list