|
Hey
Main problem with userdata is that this is about being as fast as is humanly possible! Most stuff is easy to say ‘avoid this expensive thing’, but when a simple vector operation like a = b*10+c actually evaluates to reading a vector, multiplying it by ten, allocating a new vector with the result, loading another one, adding the 2 together, allocating another one for the result and storing in a, it’s very easy to inadvertently create a lot of allocations/frees of user data (this is indeed what we were doing before and it was a real hit to performance). On testing, the principle cost came from the allocation of vectors from the heap (and freeing them during garbage collection) which is naturally not massively fast. We have to compare all this stuff to the general cost of the actual vector operations themselves – metatable lookups and heap allocation take an order of magnitude longer than the actual vector op itself! However, using a block allocator that avoids heap allocations, and building some of the operations into the vm rather than resorting to metatable lookups and function calls is far more efficient.
So short version, it is solely to do with performance. With the vector maths, every cycle counts so anything that chips away at their cost is a big win overall.
-Chris
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
On Behalf Of Andrew Starks
On Tue, Nov 11, 2014 at 12:59 PM, Tim Hill <drtimhill@gmail.com> wrote:
I think he's moved on, but it looked like he was trying to solve the problem where:
myvec = vec{x = 1, y=2}
func1(myvec) func2(myvec)
somewhere inside of func1:
myvec.x = 3
now func2's myvec has changed and he didn't want them to change, outside of func1.
But I don't believe that these semantics can be made to work as he had hoped, without pass-by-value for this object. I can't even think of how you could do that, even if you were to go crazy with it...
-Andrew
Please consider the environment before printing this email :-) This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately then delete this email. Any views expressed in this email are solely that of the individual and not representative of the company as a whole. Media Molecule Limited Company Reg No 5665849 Registered in England. ______________________________________________________________________ This email has been scanned by the Symantec Email Security.cloud service. For more information please visit http://www.symanteccloud.com ______________________________________________________________________ |