lua-users home
lua-l archive

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


As for weak values, your implementation there in luapower doesn't have
a __gc metamethod on tuples, which makes the use of weak values not
even worth the overhead it does add -- you aren't saving that much
memory since the index tables are be populated.

I'm not sure I understand this point. The use of weak tables is not an optimization, it is necessary to have a non-leaky implementation. What does __gc has to do with it?
 
In other words, there's a lot of different ways to do it, each with
advantages and disadvantages, and implementing any of these in the Lua
core would have similar tradeoffs and I'm fairly certain that you're
not going to satisfy everyone by choosing ONE of these to canonize in
the core.
 
All engineering is tradeoffs and you'll never going to satisfy anyone, that's an impossible standard which I hope Lua is not following or we'll never see anything new in Lua again.

In particular, the most obvious implementation in the core
is the non-interned hashed version, and I think people would complain
vehemently about making table reads more expensive.

Why would they get more expensive? It's the same hashmap algorithm except now the hash function is a sum of the hashes of the elements and I don't think anyone would object that that should be O(#t) as it is for strings. What am I missing?

These are, of course,
exactly the same tradeoffs you have to make doing it outside of the
core.

I disagree. A built-in tuple would not create garbage (other than the tuple itself), would not slow down the gc for _other_ objects, and would not create hash strings and I never said anything about a __hash metamethod (which would be useless without a __collision_check metamethod btw or you're back to square one, but I don't want any of that anyway).