All Projects → ruediger → mat-asm.js

ruediger / mat-asm.js

Licence: other
Simple linear algebra implementation using asm.js

Programming Languages

javascript
184084 projects - #8 most used programming language

mat-asm.js: Simple linear algebra implementation using asm.js

This is an experiment of mine to get a bit familiar with asm.js and test potential performance gains. The code is not a full linear algebra library and only supports 4×4 matrices and 3 element vectors. Its API is a bit inspired by glMatrix but not fully compatible! All of it is a work in progress and currently not really useful!

There is still a lot to do and only some basic things work (mostly untested).

It should work with any browser supporting Typed Arrays (at least current Chrome and Firefox). However to get the (potential) performance gain from asm.js a Nightly release of Firefox is required at the moment. For Ubuntu simply use the Mozilla Daily PPA.

Simply open the file index.html with Firefox Nightly and open the “Web Console” (Ctrl+Shift+K). It should print the message “Successfully compiled asm.js code”.

A major difference compared to glMatrix is the way matrices and vectors are presented to the user. In mat-asm.js the user only gets an integer which represents a “pointer” on the module internal heap. To get an array use mat4.getArray or vec3.getArray.

Contributions are welcome.

One major design drawback is that matrices and vectors are not garbage collected. To make matters worse you can’t even manually free them because at the moment the internal memory is simply used as a stack. So try to reuse pointers.

Benchmark results

For (disappointing) benchmark results check out my fork of webgl-matrix-benchmarks (mat-asm.js branch).

(In million iterations per second)

LibraryMultiplicationTranslationScalingRotation (Arbitrary axis)Rotation (X axis)TransposeInverseInverse 3x3Vector TransformationAverage
TDLFast13.0036.9856.1614.2043.3869.7610.8334.90
TDLMath3.3194.2458.7120.9869.601.333.2611.6021.3531.60
mjs16.6937.9350.8217.1622.5174.705.86 (bad)16.3921.4529.28
EWGL9.7631.6831.7613.3216.4978.406.2226.80
closure13.0218.9214.291.331.3139.0014.1525.4429.9917.49
CanvasMatrix16.870.910.960.570.5380.057.2315.30
glMatrix17.2714.9234.831.351.4016.1114.8816.7414.69
mat-asm.js3.890.990.731.267.702.622.87
Sylvester0.901.370.070.110.61
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].