<div dir="ltr">On 24 May 2013 14:11, Marco Leise <span dir="ltr"><<a href="mailto:Marco.Leise@gmx.de" target="_blank">Marco.Leise@gmx.de</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am Thu, 23 May 2013 20:21:47 -0400<br>
schrieb "Jonathan M Davis" <<a href="mailto:jmdavisProg@gmx.com">jmdavisProg@gmx.com</a>>:<br>
<div class="im"><br>
> At some point, we're probably going to need to<br>
> benchmark stuff more agressively and optimize Phobos in general more, because<br>
> it's the standard library. And eliminating unnecessary memory allocations<br>
> definitely goes along with that.<br>
><br>
> - Jonathan M Davis<br>
<br>
</div>On a related note, a while back I benchmarked the naive Phobos<br>
approach to create a Windows API (wchar) string from a D<br>
string with using alloca to convert the string on a piece of<br>
stack memory like this: <a href="http://dpaste.1azy.net/b60d37d4" target="_blank">http://dpaste.1azy.net/b60d37d4</a><br>
IIRC it was 13(!) times faster for ~100 chars of English text<br>
and 5 times for some multi-byte characters.<br>
I think this approach is too hackish for Phobos, but it<br>
demonstrates that there is much room.<br></blockquote><div><br></div><div style>I don't think it's hack-ish at all, that's precisely what the stack is there for. It would be awesome for people to use alloca in places that it makes sense.</div>
<div style>Especially in cases where the function is a leaf or leaf-stem (ie, if there is no possibility of recursion), then using the stack should be encouraged.</div><div style>For safety, obviously phobos should do something like:</div>
<div style>  void[] buffer = bytes < reasonable_anticipated_buffer_size ? alloca(bytes) : new void[bytes];</div><div style><br></div><div style>toStringz is a very common source of allocations. This alloca approach would be great in those cases, filenames in particular.</div>
</div></div></div>