D perfomance
Walter Bright
newshound2 at digitalmars.com
Sat Apr 25 22:15:44 UTC 2020
On 4/25/2020 3:34 AM, Joseph Rushton Wakeling wrote:
> In any case, I seriously doubt those kinds of optimization have anything to do
> with the web framework performance differences.
I agree. I also generally structure my code so that optimization wouldn't make a
difference. But it's still a worthwhile benefit to add it for @live functions.
> I suppose that in a more complicated app there could be some multiplicative
> impact, but where high-throughput web frameworks are concerned I'm pretty sure
> that the memory allocation and reuse strategy is going to be what makes 99% of
> the difference.
My experience is if the code has never been profiled, there's one obscure
function unexpectedly consuming the bulk of the run time, which is easily
recoded. A programs that have been runtime profiled tend to have a pretty flat
graph of which functions eat the time.
> // extract array instance from reusable pool,
> // and set its length to zero so that you can
> // write into it from the start
> x = buffer_pool.get();
> x.length = 0;
> assumeSafeAppend(x); // a cost each time you do this
>
> // now append stuff into x to
> // create your response
>
> // now publish your response
>
> // with the response published, clean
> // up by recycling the buffer back into
> // the pool
> buffer_pool.recycle(x);
>
> This is the kind of pattern that Sociomantic used a lot. In D1 it was easy
> because there was no array stomping prevention -- you could just set length == 0
> and start appending. But having to call `assumeSafeAppend` each time does carry
> a performance cost.
This is why I use OutBuffer for such activities.
> IIRC Mathias has suggested that it should be possible to tag arrays as intended
> for this kind of re-use, so that stomping prevention will never trigger, and you
> don't have to `assumeSafeAppend` each time you reduce the length.
Sounds like an idea worth exploring. How about taking point on that? But I would
be concerned about tagging such arrays, and then stomping them unintentionally,
leading to memory corruption bugs. OutBuffer is memory safe.
More information about the Digitalmars-d
mailing list