Re: specialized array slower than unspecialized?
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Sat, 31 Mar 2007 10:45:14 -0400
In article <1175349057.554480.255380@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"andrew.baine@xxxxxxxxx" <andrew.baine@xxxxxxxxx> wrote:
On Mar 30, 9:51 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:
In article <1175301662.043024.201...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
turing.incompl...@xxxxxxxxx wrote:
Hello,
I'm working on my first non-toy lisp program (a Monte Carlo simulation
code). I was experimenting with different ways of writing a function
when I accidentally noticed the following: it seems that declaring the
element-type of an array makes the code slower (and also cons more),
but I was under the impression that the opposite should be the case.
Can somebody please enlighten me? (I hope this question is not too
stupid)
If the array is specialized, then every time you extract an element from
it the system has to allocate an object to hold it -- this is
traditionally called "boxing".
On the other hand, if the array is general then it just contains
pointers to the objects, and extracting from the array just involves
returning that pointer.
Boxing can be avoided if you provide enough declarations that the
compiler can generate code that operates directly on the specialized
representation. Your code doesn't have any type declarations, so
everything ends up being done with generic code.
Very interesting -- so if you use an :element-type argument to make-
array you're not likely to get any benefit unless you also use type
declarations when you use that array?
There's still benefit in some cases. If the array is large, specialized
arrays of small integer types can use much less memory. E.g. :TYPE
(UNSIGNED-BYTE 8) will just use one byte per element, rather than 4 (or
8 if you have a 64-bit Lisp).
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- References:
- specialized array slower than unspecialized?
- From: turing . incomplete
- Re: specialized array slower than unspecialized?
- From: Barry Margolin
- Re: specialized array slower than unspecialized?
- From: andrew.baine@xxxxxxxxx
- specialized array slower than unspecialized?
- Prev by Date: Re: sharp-back syntax
- Next by Date: Re: Any macro for inserting math "normally"
- Previous by thread: Re: specialized array slower than unspecialized?
- Next by thread: Re: specialized array slower than unspecialized?
- Index(es):
Relevant Pages
|
|