[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.4-work1 with first class arrays (implementation & benchmarks)
- From: Duane Leslie <parakleta@...>
- Date: Wed, 28 Mar 2018 18:10:31 +1100
> On 28 Mar 2018, at 16:00, Petri Häkkinen <petrih3@gmail.com> wrote:
>
>> On 28 Mar 2018, at 0.56, Duane Leslie <parakleta@darkreality.org> wrote:
>>
>> The issue of length is a quirk of the language but I can't see any generic way to keep a more accurate version without cost
>
> (Naturally ‘#’ could still be implemented using metatables for tables, if so desired.)
I have to admit I haven't read your code, only the Readme, but I fail to see the difference between your proposed operation and the `.n` field and some very basic metamethods and extending the library functions which you require anyway. When I spoke about *generic* I meant a length value that was always equal to the largest index in the table.
> Also, I think you are underestimating the value of a fast # operator. For example, a benchmark doing "t[#t+1] = value" runs about 5 times faster with arrays and constant time length operator.
How about compared to using `.n` or the local variable idiom (i.e. `t[next], next = value, next+1`). `#t` is known to be slow, so where you need performance you cache it or manage it manually.
I don't know if I am convinced that automatically caching this value and having functions to manipulate it is enough of a boon to justify a new primary data type.
Regards,
Duane.