Re: optimizing simple-arrays



On Wed, 06 Apr 2005 13:11:53 +1200, Adam Warner wrote:
> The problem is that you are evaluating the initial contents at run time.
> So you would need to build a sequence at run time to pass to
> :INITIAL-CONTENTS. You'd actually build two sequences and would be likely
> to generate more garbage. That's why it's better to just make the array
> and then fill each element in.

Here's another approach where one first builds a sequence of the wrong
type and then coerces it to the correct type:

(coerce (vector (random 1f0) (random 1f0) (random 1f0))
'(simple-array single-float (*)))

While a Sufficiently Smart Compiler could transform this to code that
skips the initial generation of the type T vector, SBCL does not have such
a SSC (they're a mythical construct):

* (lambda ()
(declare (optimize (speed 3) (safety 0) (debug 0)))
(coerce (vector (random 1f0) (random 1f0) (random 1f0))\
'(simple-array single-float (*))))

; in: LAMBDA NIL
; (VECTOR (RANDOM 1.0) (RANDOM 1.0) (RANDOM 1.0))
; --> LET PROGN LET LOCALLY SETF SB-KERNEL:%SVSET SB-KERNEL:%ASET LET*
; --> SB-KERNEL:HAIRY-DATA-VECTOR-SET MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL
; --> FUNCTION
; ==>
; (SB-KERNEL:DATA-VECTOR-SET ARRAY SB-INT:INDEX SB-C::NEW-VALUE)
;
; note: doing float to pointer coercion (cost 13), for:
; the second argument of DATA-VECTOR-SET/SIMPLE-VECTOR-C
;
; note: doing float to pointer coercion (cost 13), for:
; the second argument of DATA-VECTOR-SET/SIMPLE-VECTOR-C
;
; note: doing float to pointer coercion (cost 13), for:
; the second argument of DATA-VECTOR-SET/SIMPLE-VECTOR-C
; compilation unit finished
; printed 3 notes
#<FUNCTION (LAMBDA ()) {93062DD}>

The compiler notes indicate that the randomly generated single floats are
first assigned to the vector of type T. A disassembly will also confirm
the call to ALLOCATE-VECTOR.

Regards,
Adam
.



Relevant Pages

  • Re: Optimizing numerics: a) declarations b) partial evaluation
    ... > There's another thread on the group that might be helpful: float to ... > pointer coercion (cost 13). ... Prev by Date: ...
    (comp.lang.lisp)
  • Re: Factoring - a newbie question
    ... Indeed, most Forths are optimized to minimize this cost, because of the extreme modularity that characterized Forth programming style. ... Factoring this would save 12 words and assuming I can think of a good name for the sequence, the end result should be more readable. ... The issue is often less whether factoring the sequence would save or cost and more whether the factor is a nameable concept. ... Once the word is tested, readability matters only if I have to revisit this particular word - which I think is unlikely, but one never knows. ...
    (comp.lang.forth)
  • Re: Best Match sort sequence
    ... I've tried Internet Explorer, Firefox, Netscape and Safari. ... seller status with good star ratings, high item cost, lots of existing ... Things that will count against you include postal cost being higher ... The sequence is different depending on which browser is used. ...
    (uk.people.consumers.ebay)
  • Re: Best Match sort sequence
    ... results are nothing like each other, which leads me to believe that a seller ... requiring Paypal payment at time of purchase. ... Things that will count against you include postal cost being higher ... The sequence is different depending on which browser is used. ...
    (uk.people.consumers.ebay)
  • Re: Attn: Atheists & Skeptics - Whats wrong with answersingenesis.com?
    ... >> it would take to sequence one set of DNA and change the base pairs to ... >>> John Drayton ... They wanted to get the cost ... By the time the chicken genome was sequenced ...
    (talk.origins)