lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Petri Häkkinen wrote:
> Just to be sure that we're on the same page; I think vectors should be like
> other atomic data types, e.g. like numbers, rather than being objects. This
> would eliminate the allocation cost altogether.

Well, I disagree. There are other ways to eliminate allocations.
Proper API design (pass a reference to a destination vector)
and/or adding escape analysis to the compiler will solve this in
most cases.

> Modern games are full of vector manipulation, so this is basically the only
> thing stopping us from creating big commercial quality games with LuaJIT.

Please don't spread FUD. This hasn't stopped anybody else from
creating games with LuaJIT. Most of that vector stuff is running
on the GPU or in a physics engine nowadays. Whatever is left, is
either not time-critical and/or the allocations can be eliminated.

> Basically what we did with lua-vec was to double the size of Value struct so
> that it could hold a 4D float vector. Doubling the size of every value is
> quite nasty yes, but perhaps this could be implemented better in LuaJIT...
> What do you think?

No way. Memory bandwidth is one of the top performance bottlenecks
on modern CPUs. You don't want a narrow use case to destroy the
performance of the common case.

[Case in point: 2 of the 3 leading open source JavaScript engines
have now switched to the 8 byte NaN-tagging value model that's
used by LuaJIT. Esp. Mozilla made extensive measurements before
going for such a major change of their code base. Having a compact
value representation pays off big time for dynamic languages.]

--Mike