Comments (4)
Wow! That's a pretty significant difference!
Like you, I was fairly surprised by the results so I decided to do a bit more digging, because I had benchmarked this same scenario earlier in the libraries life and found TypedArrays to be faster. So I tinkered with it a bit and eventually landed on the following: In your tests the TypedArray is slower because you create a new one every pass.
If you check out my variation of your test that creates the tests once in the setup and then reuses them for all the iterations the Typed array does come out on top. (Not by a huge margin, but it is faster).
http://jsperf.com/vec3-performances/2
This is concerning to me because it means that you won't get the performance benefits unless you are using the library the "right" way, which is obviously going to depend on the programmer. That said, glMatrix was architected in such a way as to encourage variable reuse anyway.
Finally, if you're using glMatrix with WebGL then you'd be forced to construct a new Float32Array anyway each time you passed a matrix to your shader if we forced it to use JS Arrays. That would probably nullify any performance gains you got from making the initial create faster. :(
So, long story short: I think I'm going to leave the library as-is of the moment and maybe add some more documentation about "best practices". It's probably also worthwhile to prod at the Chrome and Firefox teams to see if there's any performance gains to be had with TypedArray construction.
Thanks for pointing this issue out!
from gl-matrix.
Thanks for the tip about object creation. I'm going to try and reuse a lot my variables. I believe that typed arrays are allocated in a special memory space where malloc is more costly. Do you know a way to report this behavior to the Chrome devs?
I'm working on a ray tracer so I'm not too concerned about webgl interoperability. When I changed from Typed Array to Array and it took 1s instead of 10 I was shocked and quite happy :p
Thanks
Christopher Chedeau
On 24 déc. 2011, at 18:31, Brandon [email protected] wrote:
Wow! That's a pretty significant difference!
Like you, I was fairly surprised by the results so I decided to do a bit more digging, because I had benchmarked this same scenario earlier in the libraries life and found TypedArrays to be faster. So I tinkered with it a bit and eventually landed on the following: In your tests the TypedArray is slower because you create a new one every pass.
If you check out my variation of your test that creates the tests once in the setup and then reuses them for all the iterations the Typed array does come out on top. (Not by a huge margin, but it is faster).
http://jsperf.com/vec3-performances/2
This is concerning to me because it means that you won't get the performance benefits unless you are using the library the "right" way, which is obviously going to depend on the programmer. That said, glMatrix was architected in such a way as to encourage variable reuse anyway.
Finally, if you're using glMatrix with WebGL then you'd be forced to construct a new Float32Array anyway each time you passed a matrix to your shader if we forced it to use JS Arrays. That would probably nullify any performance gains you got from making the initial create faster. :(
So, long story short: I think I'm going to leave the library as-is of the moment and maybe add some more documentation about "best practices". It's probably also worthwhile to prod at the Chrome and Firefox teams to see if there's any performance gains to be had with TypedArray construction.
Thanks for pointing this issue out!
Reply to this email directly or view it on GitHub:
#11 (comment)
from gl-matrix.
http://fooo.fr/~vjeux/epita/raytracer/trace.html
It's work in progress but you might be interested :)
from gl-matrix.
Awesome raytracer! Thanks for sharing!
from gl-matrix.
Related Issues (20)
- Published version 3.4.3 does not contain type definitions HOT 1
- Missing frustumZO method HOT 1
- How to pass data to webgl? HOT 2
- vector equals fails if one vector is all Infinity
- Breaking change: 3.4.3 no longer has exports in package.json HOT 2
- Math.hypot is really slow HOT 4
- vec*.round(out, a) is asymmetric
- Should targetTo preserve scaling? HOT 2
- Matrix-Vector multiplication HOT 1
- glMatrix v4.0 - Request for feedback HOT 64
- Some return types don't include `null` HOT 1
- fromQuat2 allocates a vector on every call
- Functions not the same across mat4, mat3, mat2
- TypeScript types: suggest omitting Float32Array type
- `Array` vs `Float32Array`: Performance measurements (again)
- Bug: `lookAt` and `targetTo` will not work if `position` and `target` are vertical
- [BUG] build error HOT 1
- Inconsistent order or arguments HOT 1
- No Explanation on how to access functions after upgrade
- IndexedCollection type not available in releases HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gl-matrix.