Why Strings as Classes?

bearophile bearophileHUGS at lycos.com
Tue Aug 26 05:08:08 PDT 2008


Benji Smith:
> It looks like D mostly falls down when it has to allocate a lot of 
> memory, even if it's just allocating slices. The D performance for 
> string splitting really surprised me.

String splitting requires lot of work for the GC. The GC of HotSpot is light years ahead of the current D GC. You can see that measuring just the time the D GC takes to deallocate a large array of the splitted substrings.
I have posted several benchmarks here about this topic.


> I was interested to see, though, that Java was so much faster at 
> iterating through the characters in a string, since I used the charAt(i) 
> method of the CharSequence interface, rather than directly iterating 
> through a char[] array, or even calling the charAt method on the String 
> instance.

HotSpot is able to inline lot of virtual methods too, D can't do those things.


> Down with premature optimization! Design the best interfaces possible, 
> to enable the most pleasant and flexible programing idioms. The 
> performance problems can be solved. :-P

They currently can't be solved by the backends of DMD and GDC, only HotSpot (and maybe the compiler of the dot net on windows) are able to do that. I don't know if LLVM will be able to perform some of those things.

Bye,
bearophile



More information about the Digitalmars-d mailing list