Dav1dde / gl3n

OpenGL Maths for D (not glm for D).
http://dav1dde.github.com/gl3n/
Other
103 stars 49 forks source link

remove unneeded allocations #50

Open extrawurst opened 9 years ago

extrawurst commented 9 years ago

all Matrix.invert(): currently the mixin AFAIK creates a dynamic array even though the matrix already contains one, just assignments would be enough. for example: https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1036

Matrix.perspective() with FOV: https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1179

Dav1dde commented 9 years ago

I agree, but if you look at https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1127-L1158 - It's simply not feasable to do. You would need to store half of the content in local variables and access the other half on the fly (matrix[x][y]). That just generates a huge blob of unreadable code. My hope is/was that the generator somehow can optimize that to a static array (so you don't have the runtime allocation + memcpy).

extrawurst commented 9 years ago

i am not sure about this, i always thought a multidimensional array literal is constructed using gc allocations. i could be wrong.

Dav1dde commented 9 years ago

Tbh, I have no idea, I was simply assuming the optimizer has gotten good enough ... Then again, it's D/dmd. But we wont know for sure until someone runs it through a debugger/looks at the asm.

If you wanna go for it and create the ugly code required for replacing it, I will merge it. But please add unittests beforehand (the code required will be really ugly, I assume, easy to make mistakes).

extrawurst commented 9 years ago

a simple test with array literals on http://d.godbolt.org/ reveil that these create a call to _d_arrayLiteralTX that actually uses a gc_allocation: https://github.com/D-Programming-Language/druntime/blob/e47a00bff935c3f079bb567a6ec97663ba384487/src/rt/lifetime.d#L2135

so at least we now know that literals create heap traffic :(

Dav1dde commented 9 years ago

Yeah that sucks ... if even gcc doesn't optimize it. (To answer your question from IRC this morning, yes I am dav1d on freenode)