skinny delegates

Jonathan Marler johnnymarler at gmail.com
Fri Aug 3 16:46:53 UTC 2018


On Friday, 3 August 2018 at 16:19:04 UTC, kinke wrote:
> On Friday, 3 August 2018 at 14:46:59 UTC, Jonathan Marler wrote:
>> After thinking about it more I suppose it wouldn't be that 
>> complicated to implement.  For delegate literals, you already 
>> need to gather a list of all the data you need to put on the 
>> heap, and if it can all fit inside a pointer, then you can 
>> just put it there instead.
>
> Nope, immutability (and no escaping) are additional 
> requirements, as each delegate copy has its own context then, 
> as opposed to a single shared GC closure.
>

Maybe you could provide an example or 2 to demonstrate why these 
would be requirements...we may have 2 different ideas on how this 
would be implemented.

>> In the end, I think that most if not all use cases would be 
>> better off using the library solution if they want this 
>> optimization.
>
> I disagree.

I'm not sure which part you disagree with.  I was saying that 
with a library solution, you get the ability "opt-in"/"opt-out" 
of the optimization, do you think it should always be on and the 
developer shouldn't need to or care to opt out of it?  Also, what 
about the developers that want to guarantee that the optimization 
is occuring? If they just stick a @nogc around it then how would 
they determine which requirement they are violating for the 
optimization to occur?



More information about the Digitalmars-d mailing list