About structs and performant handling

deadalnix deadalnix at gmail.com
Tue Mar 12 00:32:14 PDT 2013


On Tuesday, 12 March 2013 at 06:36:32 UTC, Zach the Mystic wrote:
> Your point reminds me of the fact that D has no "inline" or 
> "register" keywords. You probably couldn't pick better experts 
> than the D compiler builders for deciding whether or not those 
> two keywords are necessary. I guess there's not a clear 
> solution to this question, or it would have been settled a 
> while ago. Maybe it should be called the "performance ref" 
> issue, to distinguish it from other ref issues, "@safe ref", 
> "auto ref", etc.

Register keyword make no sense nowadays. Compiler can figure it 
out way better than you. You could forget about some register 
keyword and slow down you program for nothing. You could use some 
register keyword and create bug because you got your aliasing 
wrong. And all that would require a huge amount of work and 
clutter the codebase. register keyword is a relic from the past, 
even in C.

inlining is more subtle. In the general case, compiler get it 
better than humans, however, it is a much harder problem than 
register, so being able to hint the compiler may be useful. 
However, the usage of this is limited to very specific use cases.

I don't see any reason to not allow the compiler to do so and 
create copy on a per needed basis, by optimizing pass-by value 
into pass-by-reference when it can prove it doesn't change the 
semantic (see my thread on the topic, but modify it to apply the 
restriction to anything possibly aliased).

For the same reason as inline and register, I do think the 
default behavior is to let the compiler choose what is the bast 
as long as it doesn't change the final behavior.


More information about the Digitalmars-d mailing list