lua-users home
lua-l archive

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

On Sat, Aug 27, 2011 at 10:55, Dirk Laurie <> wrote:
> On Fri, Aug 26, 2011 at 07:17:10PM +0200, Alexander Gladysh wrote:
>> On Fri, Aug 26, 2011 at 21:09, Mike Pall <> wrote:

>> > pairs() will not be fast, no matter what I do.

>> So, any code that uses pairs() is bound to be interpreter-only, is this
>> correct?

> pairs() traverses all actually used entries in a hash table.  Although
> in theory it takes O(n) time to traverse n pairs, in practice the big-O
> hides a fairly substantial factor compared to ipairs().  Even if you
> hand-code everything directly in assembler (which LuaJIT nearly does).

I most likely am missing something about how LuaJIT works, so please
correct me if I'm wrong:

1. I'm content with the fact that the pairs() would always be slow.

2. However, if pairs() abort the trace of any function...

3. ...Then that *any* function may never be compiled to the native code.

4. And that function may do something complex and optimizable besides
calling pairs()...

5. ...Which would never be optimized due to #3.

So, should I, for example, move the body of a loop with pairs() to the
separate function so it would be compiled? Or what?