Archive for March 2010

EWGL-matrices   1 comment

Hey there,

As many may already know, I’ve started writing EWGL-Matrices. It is the fastest 4×4 matrix library around ;). Although it is the fastest around, it still can be increased in speed by removing the object matrix and just use methods like mjs does. And Even that library could get faster if needed. (I am thinking of the way assembly calculates) . So we’re not even close to our end goal but we are getting there. But for the moment I am going to talk what EWGL-matrices does do to increase speed.

But First some comments. Everything We did to increase the speed is completely compliant with the JavaScript spec. So every Browser supporting WebglFloatArray and has a decent JavaScript interpreter will have no troubles with EWGL-matrices. Secondly, I want to thank everyone who helped me create this Library. It couldn’t beat that ridiculous fast mjs in even 1 function. Thirdly, Vlad really helped to bring things even faster because of his ridiculous fast mjs library. Hehe, I stole some ideas from him.

EWGL-matrices lowers the burden on creating a new matrix by only having one newly created element in its initialization, elements. All it’s methods are in the prototype of that matrix object. But why would that be so important?? Well Every time you duplicate a matrix it needs to create a new matrix. That is why a new matrix needs to be fast.

But why did I choose to work with my elements closed into a WebglFloatArray and not into an array like Everyone. Well that is only after some tests done of course. When I first tested an WebglFloatArray against an Array, It was a lot slower. (begin days of webgl) But then After a few months I noticed a shift, WebglFloatArray was getting at the speed of arrays or is now even faster than arrays. That was 1 factor of course but there is still another factor that made me decide on WebglFloatArray. That was the fact that everyone uses New WebglFloatArray for every matrix sent. Which is not only not needed anymore thanks to the WebglFloatArray in the matrix but it also helps the garbage collecting that doesn’t need to collect all these empty WebglFloatArray which also decreases the speed although less measurable (so you need to believe me on my word for that. Sorry about that). So WebglFloatArray is not slower then arrays and it doesn’t need conversions and It doesn’t waste GC resources. Enough reasons I guess to use WebglFloatArray.

But that is not all to it because there are other libraries that do the same but don’t achieve the same speed. Another thing is using no loops and no functions in our methods because we don’t need them. No functions means no closures created and no everything around it which is again an speed increase. No loops are needed because we always know for sure there are 16 elements in the matrix (4×4= 16 😉 ). So everything is written out as much as possible.

And last but not least, There is a the fact that caching also exists. This is of course possible because of javascript taking references of objects. And because a saving a reference and using that is faster than looking the same thing up 2. So we use a lot of caching in EWGL-matrices.

Well There is more of course like using ternary statements over if statements and using || and && over ternary statements but this was about everything that made it fast.

But I said, We could make it even faster, So why didn’t We. I wanted a fast matrix object oriented library, So just for my connivance isn’t it. But that doesn’t mean I am going to stop now. But everyone knows by now that mjs can become faster. This will be my next project if I can find time. And then We will go to the next matrix library called EWGL-amjs (A stands for assembly) . Of course again based on mjs (I really like that library, don’t I) . But that is still something that is only a idea I still need to really test it.
I hope Now to see better library for webgl. And many more improvements based on this article.

Ps: I was really queit lately because I found a job but It won’t better soon so I can only hope It will improve. I’ve written this post becuase many couldn’t believe how I could achieve this speed.

Posted March 25, 2010 by ewgl in webGL

Tagged with , ,