On Friday, 12 June 2015 at 11:06:43 UTC, Dicebot wrote:
The legendary allocator package by Andrei Alexandrescu has arrived at your doorsteps and kindly asks to let it into Phobos

Sorry for being late, I wanted to restate an idea that could be crucial for optimizations.
https://github.com/D-Programming-Language/druntime/pull/1183#issuecomment-77065554

This reminds me of the fact, that the IAllocator interface (std.allocator) should also have a strongly pure allocate function. This might allow the compiler to optimize allocations even with a dynamic dispatch allocator, because it assumes that an allocation doesn't have a side-effect and always returns "fresh" unaliased memory.

Chandler Carruth was talking about this problem at the last CppCon.
https://www.youtube.com/watch?v=fHNmRkzxHWs&t=3950
https://www.youtube.com/watch?v=fHNmRkzxHWs&t=4037

Now putting pure onto the allocate function of IAllocator would be a very harsh constraint for any implementation. So maybe we could employ a compiler hack, marking any IAllocator.allocate implementation as pure.

This optimization is really important, b/c it allows the compiler to ellide allocations when it can compute something using a temporary buffer. It'd probably require a magic free as well, so that the compiler knows the lifetime and sees that data isn't escaped.

Reply via email to