[cfe-dev] Question about optimization of new and delete
Stephan Tolksdorf
st at quanttec.com
Tue Oct 1 04:39:14 PDT 2013
Hal Finkel wrote:
>> Capping the total size seems more reasonable to me, but as you said,
>> it's necessary to experiment.
>> Anyway, I was thinking about a tradeoff between stack usage and speed
>> based on the "hotness" of the code (how to call it?). For example a
>> relatively big allocation inside a tight loop might be lowered while
>> an allocation of the same size at function scope would not.
>> Also, I think the function being recursive and/but getting
>> transformed by tail call elimination should be factors to take into
>> account.
>>
>> What do you think?
>
> These all seem like good ideas; once the initial support lands upstream, please play with it. I think that user feedback is really going to be the only way to set these various thresholds.
Stack space constraints can vary so greatly in practice that it might be
a good idea to make these thresholds user-adjustable through compiler
switches, pragmas or function attributes.
The default thresholds for optimizing allocations in non-leaf functions
should probably be very low, as you otherwise risk blowing up programs
like e.g. deeply recursive parsers or network servers with a million
lightweight threads.
To monitor the effects of such an optimization it would be nice if the
compiler could optionally output some information on the minimum and
maximum stack usage of functions.
I also suspect that the effectiveness of this optimization will depend a
lot on whether functions can be opportunistically inlined for it.
- Stephan
More information about the cfe-dev
mailing list