lua-users home
lua-l archive

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


While I do not know of any project implementing this optimisation there will be problems with the Lua C API. The manual specifies for pointers to strings in https://www.lua.org/manual/5.4/manual.html#4.1.3 "The API guarantees that any pointer to a string in a stack index is valid while the string value at that index is not removed from the stack. (It can be moved to another index, though.)". This might be a problem for the SSO since it would need to create a heap string whenever a C function tries to get a pointer to the string since it could be moved to a different stack index and the pointer still needs to be valid. Since the string library uses the Lua C API all the functions would require the arguments to be allocated on the heap. To solve this issue the string library would need to be changed to use internal functions which are aware of the SSO.

Further, nodes from the hash part of a table save the type tag and value of the key seperate:
typedef union Node {
  struct NodeKey {
    TValuefields;  /* fields for value */
    lu_byte key_tt;  /* key type */
    int next;  /* for chaining */
    Value key_val;  /* key value */
  } u;
  TValue i_val;  /* direct access to node's value as a proper 'TValue' */
} Node;

And also in the stack:
typedef union StackValue {
  TValue val;
  struct {
    TValuefields;
    unsigned short delta;
  } tbclist;
} StackValue;

While the hash table node and the stack value can be changed easily I am not certain that the C API restrictions can be solved nicely. However, it should be possible to change the string library to use lua internals to access the small strings and with the assumtion that no C modules are used this could speed strings up.

Regards,
Xmilia