Performance improvements for D / DMD compiler.
Bill Baxter
dnewsgroup at billbaxter.com
Sat Jan 20 00:46:07 PST 2007
Bill Baxter wrote:
> Walter Bright wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
>>> No, and for a good reason:
>>>
>>> foo(LargeStruct s1, LargeStruct s2)
>>> {
>>> ...
>>> }
>>> ...
>>> LargeStruct s;
>>> foo(s, s);
>>>
>>> Nobody would enjoy hidden aliasing of s1 and s2.
>>
>> There's another aliasing case:
>>
>> LargeStruct s;
>> foo(s);
>> ... here some other thread modifies s ...
This exists in C++ with const reference parameters. But I've not heard
much gnashing of teeth over this. Maybe people are getting worried
about it more these days, but since I started learning C++ I've seen
lots of code that uses const references all over the place.
But I can see that it is important to make the distinction in the header
for those who are writing multithreaded code.
Which leaves us with two alternatives:
1) add some sort of const-reference construct to D
2) leave it as is.
I have to say that 2) is probably going to send me packing. I've always
assumed that D would get some sort of const reference someday but it
sounds like you're saying you don't see a need.
But I think this raytracer example shows very clearly that using even
moderately sized structs (i.e. 3-6 floats, not even that big) as
parameters in critical loops can degrade performance significantly.
Switching to a class is not really an option. That's going to be even
slower given that intermediate vector calculations are needed all over
the place.
So the other option is scope classes which someone suggested on the
other thread. Is this really an option? I haven't played with it that
much, so I don't really know what the issues are or what the syntax
looks like in practice. But I believe at least that it means every
place you use LargeStruct you're going to have to say 'scope
LargeStruct', right? That's fairly ugly to have to say everywhere for
something that's going to get heavy use. Especially when in the end it
really *is* a value type. So it should be a struct. Period.
--bb
More information about the Digitalmars-d
mailing list