Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unneeded allocations #50

Open
extrawurst opened this issue Mar 23, 2015 · 5 comments
Open

remove unneeded allocations #50

extrawurst opened this issue Mar 23, 2015 · 5 comments

Comments

@extrawurst
Copy link
Contributor

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

@extrawurst extrawurst changed the title Matrix.invert() method without allocation remove unneeded allocations Mar 23, 2015
@Dav1dde
Copy link
Owner

Dav1dde commented Mar 23, 2015

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
Copy link
Contributor Author

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

@Dav1dde
Copy link
Owner

Dav1dde commented Mar 24, 2015

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
Copy link
Contributor Author

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
Copy link
Owner

Dav1dde commented Mar 24, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants