lua-users home
lua-l archive

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


> On 3 November 2015 at 13:26, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
>> Did you consider an inline expansion of short string keys? You could
>> do a loop unrolling of 'luaH_getstr'. (With 2 steps, I believe you
>> get a very high percentage of hits.) It is not the same as the
>> above expansion for integer keys, but it could be a reasonable
>> compromise.
>>
>
> No I hadn't considered that - thanks for the idea! If the parser knows
> that the variable is a table (static typing can tell it that) - and
> the key is a literal short string (which I believe the parser already
> knows from the fact that it is a constant) - then yes, it should be
> possible to generate inline code for the initial attempt to access the
> element - and failing that either try again as you suggest or fallback
> on calling the function luaH_getstr().
>

Roberto - thanks again for the idea ... I have done some preliminary
work, experimenting with new opcodes that are specialized for table
access with string or numeric keys. Example below. This will allow me
to generate more efficient code for table field level access :)

function x()
   local t: table = {}
   t.name = 'dibyendu'
   return t.name
end
ravi.dumplua(x)

function <stdin:1,5> (5 instructions at 0000003722946C60)
0 params, 2 slots, 0 upvalues, 1 local, 2 constants, 0 functions
        1       [2]     NEWTABLE        0 0 0
        2       [3]     SETTABLES       0 -1 -2
        3       [4]     GETTABLES       1 0 -1
        4       [4]     RETURN          1 2
        5       [5]     RETURN          0 1
constants (2) for 0000003722946C60:
        1       "name"
        2       "dibyendu"
locals (1) for 0000003722946C60:
        0       t       2       6
upvalues (0) for 0000003722946C60:
> x()
dibyendu