Rich Hickey's slides from jvm lang summit - worth a read?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Tue Sep 29 01:00:59 PDT 2009
bearophile wrote:
> Walter Bright:
>
>> I've been thinking of transitioning dmd's semantic analysis to using immutable data structures because it will reduce allocations, not increase them.<
>
> As usual I am ignorant about such matters, so I can't give you a good answer.
> But from what I've seen in immutable-based languages, they produce a sustained flux of small/little immutable objects that the GC has to free and allocate all the time. This stresses the GC. Surely people here that know Clojure or Scala, Haskell or F# may give you a better answer. Maybe even numbers of the amount of object flux they face in normal programs. So the situation with strings may be not generalizable to the other immutable data structures a program may need to use.
>
> Bye,
> bearophile
My personal experience with Scala, at least, has been that it doesn't hurt anything. Even
just considering the most common kinds of operations: ( 1 :: 2 :: 3 :: 4 :: 5 :: Nil )
creates a Scala list of five values... but in the process creates five different lists!
Consider it "unrolled" to something like this:
tmp = 5 :: Nil
tmp = 4 :: tmp
tmp = 3 :: tmp
tmp = 2 :: tmp
tmp = 1 :: tmp
tmp
Yipes. BUT... think of it as a single-linked-list structure, and its not really that bad,
because each of those objects is quite small, and all five of them are preserved in the
original list. Compare:
A = 3 :: 4 :: Nil
B = 2 :: a
C = 1 :: a
Here we have two lists (B & C) being made, each with four items... but only four items
total, not eight, because the '4' and '3' cells in A are being reused between them. I
think that kind of capability is what has Walter interested.
-- Chris Nicholson-Sauls
P.S. -- Just to make your head hurt... "::" isn't even an operator, its the name of a
class (& a singleton too...) defined in the stdlib as a derivative of List. Scala is just
weird like that.
More information about the Digitalmars-d
mailing list