What should happen here?

max haughton maxhaton at gmail.com
Sun Sep 26 20:44:48 UTC 2021


On Sunday, 26 September 2021 at 20:39:48 UTC, Steven 
Schveighoffer wrote:
> 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:
>>>>[...]
>>>
>>> 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

I think Amaury means that the code would be slower if the 
compiler is unable to register allocate at all vs. just for 
things returned by the allocator.


More information about the Digitalmars-d mailing list