[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



I've got a global variable *FOO* that is declared to be of type
short-float.  I used to have an inner loop, executed many millions of
times, that did something like the following:

(incf (the short-float *foo*) (the short-float <increment>))

OK, this is a loss.  Because *FOO* is a special, this conses a short-float
on the heap every time the function is executed, so I spend a lot of time
in GC.

So instead of that, I now do something like the following:

(let ((local-foo 0.0))
  (declare (short-float local-foo))
  (dotimes ...
    (incf (the short-float local-foo)
          (the short-float <increment>)))
  (setq *foo* local-foo))

Unfortunately, instead of just doing a heap-allocation of the flonum at the
point of the final SETQ, Python seems to believe that because of this SETQ
it has to put stack-allocated short-floats into LOCAL-FOO.  So the
inner-loop consing doesn't go away.  If I eliminate the SETQ, then the
consing goes away, but I really need to get the result into a special at
the end of the loop.

Am I doing something wrong?  If it's Python being stupid, can it be made
smarter about this?

-- Scott