Hi guys.
I forgot to say that I talked about class extending Array or extending Object in fact. I meant make my Vector class an extension of Array of a simple Object with some properties.
In this case, my vector class with properties is much faster than accessing to array members [0] corresponding to the x property.
Now I totally agree that Array and Object give the same speed (thanks Jim and Moses for your tests).
But as we are discussing about technical speed problems, I don't understand why make my vector an object like this : v = {x:1, y:25, z:7} is much faster (300%) than doing v = new Vector(1,25,7) (imagine a simple Vector class with x,y,z public properties). And it's still available (the speed difference) when we access to the properties (like r =
v.x+v.y+v.z).
Why a so simple class (vector) is such slower comparing to Object ?
++
2005/12/2, Thomas <[EMAIL PROTECTED]>:
Thanks Nicolas for this explanation :)
Well in player 7 and 8 I've noticed that array access is slower than
object property access (I can't make a tests now :S)
Something I've noticed and seems strange to me is that there is a huge
difference of performance when I use a simple Vector class (with 4
properties for exemple) and an Object instance. Properties access is
really faster in the object instance (maybe because it's dynamic, so
no property existence check ?).
Tim I think there is an important difference between player6 and
player8 that can explain my results and yours. I've read that since
player7 we have access to a most important number of registers (only 4
in player6 i think). As the access to registers is much faster, the
bytecode has been optimized to use them, and maybe make the difference
between our tests.
I'm sure that Nicolas can clarify this :)
++
2005/12/1, Tim Knip <[EMAIL PROTECTED]>:
> Nicolas,
>
> > I think there shouldn't be any difference between using array and objects.
> Thanks for clarifying this (and for MTASC ;-).
>
> > But actually, it's depending on the way
> > field tables are implemented in Flash Player.
> Mmm... Maybe I *should* make another test...
>
> Thomas:
> > Have you got an example ?
> only did some superficial testing in Flash6 days. So I'm hardly 100% sure.
>
> I think 'speed' in Flash-3D is mostly depending on how efficient the Matrix
> calculations are.
>
> Lets take most common 3D op: matrix(4x4) multiplication.
> With Object's you have to do:
> 1. M[0][0] = (v.x * m.A.a) + (v.y * m.A.b) + (v.z * m.A.c) + m.A.d
> 2. M[0][1] = ( v.x * m.B.a) + (v.y * m.B.b) + (v.z * m.B.c) + m.B.d
> ...
> 12. M[3][3] = (v.x) * etc.
>
> With Array:
> for(var i = 0; i < 4; i++) {
> M[i][0] = (v[0] * m[i][0]) + (v[1] * m[i][1]) + etc...
> M[i][1] = (v[0] * m[i][0]) + (v[1] * m[i][1]) + etc...
> M[i][2] = (v[0] * m[i][0]) + (v[1] * m[i][1]) + etc...
> M[i][3] = (v[0] * m[i][0]) + (v[1] * m[i][1]) + etc...
> }
>
> Question is: would there be difference in speed here? Guess if (Object ==
> Array) there should not. Or would the implementation of fieldtables
> (whatever they are) favour performance of one?
>
> T
>
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] Namens
> Nicolas Cannasse
> Verzonden: donderdag 1 december 2005 16:32
> Aan: Open Source Flash Mailing List
> Onderwerp: Re: [osflash] class extends Array woes
>
> Thomas wrote:
> > Hi
> >
> >>>The code is part of a 3D-engine. Array-access is supposed to be faster
> then
> >>>Object-prop-access (did some testing on it).
> >
> >
> > Are you sure ? Because I've made some tests too when I've developped
> > matrix and vector class of sandy ( 3D engine available here :
> > http://www.osflash.org/sandy ), but my tests showed that Array access
> > is much slower.
> >
> > Have you got an example ?
> > THanks
> > THomas
>
> Array access produces exactly the same bytecode as object access. That
> means that a[0] is same as doing a.0 (if it was possible). Since Arrays
> are also treated as objects, I think there shouldn't be any difference
> between using array and objects. But actually, it's depending on the way
> field tables are implemented in Flash Player.
>
> Nicolas
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>
>
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
_______________________________________________ osflash mailing list [email protected] http://osflash.org/mailman/listinfo/osflash_osflash.org
