Shared keyword and the GC?

Araq rumpf_a at web.de
Wed Oct 24 10:42:48 PDT 2012


> I haven't seen proper benchmarks but some time ago I wrote in D 
> and OCaml  basically the same simple program which read and 
> parsed some text and performed some calculations, allocating a 
> lot of temporary arrays or lists:
> https://gist.github.com/2902247
> https://gist.github.com/2922399
> and OCaml version was 2 times faster than D (29 and 59 seconds 
> on input file of 1 million lines). After disabling GC on 
> reading/parsing stage and doing calculations without 
> allocations and using std.parallelism I made D version work in 
> 4.4 seconds.
>
And that makes it the "fastest GC ever made"?

> One place where immutability really helps is in a generational 
> GC: runtime needs to track all the pointers from old generation 
> to the young generation, if most of the data is immutable there 
> are not so many such pointers, this makes collection faster. 
> When all data is immutable there is no such pointers at all, 
> each object can only have pointers to older ones.

That's true. But you don't need to know about immmutability at 
compile time to get this benefit.



More information about the Digitalmars-d mailing list