What should happen here?

Steven Schveighoffer schveiguy at gmail.com
Sun Sep 26 20:39:48 UTC 2021


On 9/26/21 3:13 PM, deadalnix wrote:
> On Friday, 24 September 2021 at 15:31:46 UTC, Steven Schveighoffer wrote:
>> On 9/24/21 11:25 AM, deadalnix wrote:
>>> On Thursday, 23 September 2021 at 19:54:56 UTC, Steven Schveighoffer 
>>> wrote:
>>>> You can. But wouldn't you prefer just pushing something on the stack?
>>>>
>>>
>>> Not really. If the optimizer can remove dead stack pushes, then 
>>> program will become 2x slower instantly in addition of consuming more 
>>> stack memory.
>>>
>>
>> You think pushing on the stack is going be 2x slower than calling 
>> `GC.addRoot`?
> 
> If the optimizer isn't free to optimize thing away from the stack, yes, 
> it's pretty much guaranteed.

You realize what `GC.addRoot` does? It adds a pointer to a treap, 
through a virtual function call after taking a global lock. Pushing a 
stack item is going to be at least 10x faster, probably more compared to 
that. In the function call alone, there are a few stack pushes.

-Steve


More information about the Digitalmars-d mailing list