lua-users home
lua-l archive

Re: using array nature for microoptimization

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


> In Lua 5, tables are implemented as having two parts: an array part,
> consisting of integer-keyed values, and a general hash table part. A
> key is a candidate for the array part if the array part is mostly
> consecutive. (This way assigning to t[20000] will not allocate a 20000
> element array part, unless t[1]...t[19999] is already mostly used.)
What happens is that the array part is used for numeric indices 1..n such
that at least half the entries in 1..n are non-nil.
> The array part seems much faster.
It should be, there's no hash function to call nor chains to follow.
> which I think was entirely stored as a hash table.
> Also, if you plan on doing a lot of unpack() calls on prepared tables
> you construct, add an "n=3" to your {"start", "b", {}, n=3} tables.
> That was good for another 5% speedup....
Interesting.
Have you put this on the Wiki?
-- 
http://www.mupsych.org/~rrt/ | perfect, a. unsatirizable

AltStyle によって変換されたページ (->オリジナル) /