[racket] static variables question

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Feb 19 16:30:25 EST 2012

The compiler does not track if a function always returns the same
results to the same inputs, and even if it did, it would have to
figure out where to save the results to reuse them the next time,
something that is tricky to do in the general case. Anyways, doing
this kind of optimization is not something that compilers generally
do, fwiw.


On Sun, Feb 19, 2012 at 12:29 PM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> Joe Gilray wrote at 02/19/2012 12:52 PM:
>>    You are doing "(integer-sqrt x)" a few times, when "x" can't
>>    change in between.  You might want to have the code look like
>>    "(integer-sqrt x)" is computed only once in the block of code in
>>    which "x" can't change.  Just good practice, IMHO; I don't promise
>>    that it makes a performance difference.
>> Hmmm, yes, I left that as an exercise for the compiler!  More seriously,
>> will the Racket compiler optimizes those calls?
> Matthew F. could answer this authoritatively, but I think that a good, if
> vague, general practice is to not rely on fancy compiler optimizations for
> things that you can instead reasonably do in code.  Also, for now, I assume
> that the code will run on a single CPU, so automatic parallelization won't
> save one from the cost of multiple identical function evaluations (although
> I do secretly fantasize about things like "let" clauses someday being run in
> parallel).  It's pretty intuitive for single-CPU; parallel is harder to
> reason about.
> Sam T-H's disassembler might also be helpful:
> http://lists.racket-lang.org/dev/archive/2011-January/005321.html
> That said, I suggest trying not to worry too much about optimal run-time
> speed at this point, and focus first on learning idiomatic Racket.  I am
> sympathetic, though; here is something I wrote when I was starting to learn
> Scheme, in 2001: "One of the few drawbacks I'm finding to Scheme hacking is
> that I'm painfully conscious of performance issues when writing reusable
> modules, but the low-level execution model of a particular Scheme
> implementation is much more opaque than that of a C compiler. For most
> rapid-prototyping application work, Scheme is a big win, but I find myself
> cringing those few times when I'm struggling with how to do something
> efficiently in Scheme and happen to think of an elegant and super-fast C
> implementation."
>> Interesting!  Is there a Racket profiler available?
> Yes, if you search the docs or the Web, you'll find at least two profilers.
>  This one is the most useful for now, although it's not integrated into
> DrRacket: http://docs.racket-lang.org/profile/index.html
> --
> http://www.neilvandyke.org/
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

Posted on the users mailing list.