Discussion:
[Larceny-users] make-bytevector and bytevector-copy
Eduardo Cavazos
2009-02-15 19:38:34 UTC
Permalink
Hello,

When profiling my program, I notice 'get-modelview-matrix' is
consistently high in the list. Here it is:

(define (get-modelview-matrix)
(let ((bv (make-bytevector (* 16 8))))
(glGetDoublev GL_MODELVIEW_MATRIX bv)
bv))

I could write it like this:

(define get-modelview-matrix
(let ((bv (make-bytevector (* 16 8))))
(lambda ()
(glGetDoublev GL_MODELVIEW_MATRIX bv)
bv)))

That's of course much faster. But, one of the callers of
'get-modelview-matrix' really does need a copy of the matrix. So I
modified the call site as such:

(bytevector-copy (get-modelview-matrix))

and then 'bytevector-copy' shows up high in the list. :-)

So my question is, is the first version of 'get-modelview-matrix' shown
above inherently "hot"?

Ed
William D Clinger
2009-02-16 01:19:30 UTC
Permalink
Post by Eduardo Cavazos
So my question is, is the first version of 'get-modelview-matrix'
shown above inherently "hot"?
Maybe. The other possibilities are that
(glGetDoublev GL_MODELVIEW_MATRIX bv) takes a long
time or that the profiler is overcounting calls to
foreign procedures for some reason.

In any case, calling bytevector-copy instead of
make-bytevector won't buy you much (if anything),
and it may make your code harder to understand or
to debug. There's no reason why bytevector-copy
should run faster than make-bytevector; in fact,
I'd expect make-bytevector to run faster than
bytevector-copy.

Will

Loading...