March 12, 2013 Re: About structs and performant handling | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | One option, that I could think of why one should mark such parameters, would be that the compiler can then point out what is missing so that it would be potentially possible. Example: void foo (A a) { Because 'a' is not const and not scope, the compiler could not change the behavior from passing by value to passing by reference. But when the parameter is marked accordingly: void foo (A& a) { You get an error / warning: "Parameters with '&' require const scope." Whether 'A' ultimately is really big enough to make it worthwhile to have it passed by ref is irrelevant for that. |
May 08, 2013 Re: About structs and performant handling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Saturday, 9 March 2013 at 23:07:50 UTC, Ali Çehreli wrote:
> On 03/09/2013 12:19 PM, Namespace wrote:
>
> > But structs with a bigger size aren't that performant if you
> pass them
> > as copy or move them (See also my small benchmark:
>
> I have started working on the DConf presentation about copy and move semantics in D. I have done exactly the same type of tests and was surprised how faster pass-by-reference can be.
Hey, could you please publish your slides of your DConf presentation? :)
|
May 08, 2013 Re: About structs and performant handling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On 05/08/2013 05:57 AM, Namespace wrote: > On Saturday, 9 March 2013 at 23:07:50 UTC, Ali Çehreli wrote: >> On 03/09/2013 12:19 PM, Namespace wrote: >> >> > But structs with a bigger size aren't that performant if you >> pass them >> > as copy or move them (See also my small benchmark: >> >> I have started working on the DConf presentation about copy and move >> semantics in D. I have done exactly the same type of tests and was >> surprised how faster pass-by-reference can be. > > Hey, could you please publish your slides of your DConf presentation? :) Yes, they are here: http://acehreli.org/AliCehreli_copy_move_D.pdf But I see that you have been after some test results between by-copy vs. by-ref parameters. I have decided not to include them in the presentation for various reasons: not enough presentation time, not trusting my synthetic tests enough to be sure that I was covering all aspects of the behaviors of modern cpu architectures, etc. I can say that by-value was almost always slower in my little test. However, as others have been saying, by-ref can be slower if a lot of the members of the struct are accessed through that reference, effectively defeating the CPU caches. For me to see that by-ref was slower, I had to define huge structs, put them in huge arrays, and touch all of the members of random elements of that array: // s1 and s2 are random elements of huge arrays void foo(ref const(S) s1, ref const(S) s2) { // use all members of s1 and s2 } Only then by-ref was slower than by-value. Let me build more trust in my test before opening it to discussion on the forums. Ali |
May 08, 2013 Re: About structs and performant handling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | I was wondering where I can find your benchmarks as I read your slides. Now it has become clearer. I'm looking forward to reading your benchmarks and assessments. :) |
Copyright © 1999-2021 by the D Language Foundation