google-code-export / box2dweb

Automatically exported from code.google.com/p/box2dweb
0 stars 0 forks source link

Matrix/Vector coomputations #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've adapted the mjs 3D vector/matrix javascript library to 2D.
Link: http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/

It's an efficient library that minimizes object allocation and uses native 
float arrays provided by WebGL when available, but also gracefully falling back 
to javascript arrays.

It might be worthwhile porting all Box2Dweb vector math to use this lib. I 
haven't made any benchmarks myself, but here are the ones for the 3D lib 
(quoting):

The test is simple: it multiplies two matrices together in a loop 1,000,000 
times.

Test    Time
mjs, JIT, matrix reuse             140 ms
mjs, JIT, no reuse             533 ms
Sylvester, JIT, no reuse     5,280 ms
mjs, no JIT, matrix reuse   25,833 ms
mjs, no JIT, no reuse           26,681 ms
Sylvester, no JIT, no reuse 41,996 ms
Native C++, SSE2, matrix reuse      71 ms
Native C++, SSE2, no reuse     142 ms

It's a small library, easy to port, but if you're interested, it's already 
attached here.

Original issue reported on code.google.com by ushiferr...@gmail.com on 28 Sep 2010 at 6:05

Attachments:

GoogleCodeExporter commented 9 years ago
Sounds very interesting. Do you think, the perfomance remains just as well, if 
I wrap the b2Vec2 class around the library?

Otherwise I have to adjust my converter just for the vector calculations, which 
would take a lot of time. Furthermore I would have to change the documentation.

Original comment by Uli.He...@googlemail.com on 29 Sep 2010 at 3:16

GoogleCodeExporter commented 9 years ago
I started rearranging my ActionScript parser. When everything is ready I'll be 
able to convert b2Vecs as suggested.

Howevery there are some problems.
The main problem of type-tracking is the variant data type as shown in the 
code-snippet:
{{{
var u = new b2Vec2;
f(u);
function f(param:*):void { param.Set(4, 5); };
}}}

my current plan is adding conditions to function bodies if a symbol appears, 
which is possibly a member of b2Vec2 (e.g. "Set")

Other suggestions are appreciated.

Original comment by Uli.He...@googlemail.com on 30 Oct 2010 at 6:47

GoogleCodeExporter commented 9 years ago
I've got a comparison of the speed of different matrix libraries that work with 
WebGL here: 
http://stepheneb.github.com/webgl-matrix-benchmarks/matrix_benchmark.html

There are striking differences in the relative performance the when comparing 
Chrome and FF. For example the Closure library is fastest on Chrome (not 
surprising) but on FF V5 Closure and glMatrix, TDLFast and mjs are all quite 
similar in performance. 

I'm using the glMatrix library in some projects because it works well AND it 
works on both WebGL and non-WebGL-enabled browsers.

Original comment by sbanna...@concord.org on 15 Aug 2011 at 6:47