auto ref is on the docket

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 23 13:07:32 PDT 2015


On Tuesday, 23 June 2015 at 17:05:41 UTC, John Colvin wrote:
> On Tuesday, 23 June 2015 at 16:27:34 UTC, Jonathan M Davis 
> wrote:
>> On Tuesday, 23 June 2015 at 13:52:19 UTC, Daniel N wrote:
>>> On Tuesday, 23 June 2015 at 11:03:10 UTC, Jonathan M Davis 
>>> wrote:
>>>> [...]
>>>
>>> Thus the solution cannot require const.
>>>
>>> auto is worse because, if you later decide you need to add a 
>>> template parameter then the meaning is changed and you get a 
>>> _hidden_ performance issue.
>>
>> And how does it introduce a hidden performance issue. You'd 
>> end up with some template bloat, but that's it, and that's 
>> just going to increase the memory footprint of your program 
>> slightly, which isn't generally going to be a performance 
>> issue. It's just going to make your program slightly larger.
>>
>> - Jonathan M Davis
>
> instruction cache misses can really hurt

Well, if you're caring about stuff on that level, then you really 
need to understand what kind of code the compiler is generating, 
and most anything you do to the program risks changing its 
performance. So, I don't see much reason to worry about how a 
slight increase in program size from templatizing a function 
using auto ref could introduce cache misses. The fact alone that 
you've templatized the function could change its code gen enough 
to do that given that the compiler is then guaranteed to have the 
code available and will be doing attribute inference and whatnot. 
And most code probably won't see a performance difference anyway. 
Performance-intensive stuff may care, but you need to be very 
careful when tweaking that sort of code anyway, simply because 
all kinds of small tweaks can have unexpected impacts on 
performance.

- Jonathan M Davis


More information about the Digitalmars-d mailing list