lua-users home
lua-l archive

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

Em seg., 9 de ago. de 2021 às 11:35, Egor Skriptunoff <> escreveu:
On Mon, Aug 9, 2021 at 4:49 PM tehtmi wrote:

Description of my answer, in rot13, in case anyone else wants to try:

Qrpyner n pbafg fgevat gung vf irel ybat. Gura qrsvar n ybg bs shapgvbaf gung hfr vg.

BTW, it's a great idea to use rot13 for spoilers.

A note concerning this optimization used by Lua:

The increased size of a bytecode is usually not a problem.
But increased loading of CPU cache is always a performance hit.
Assigning a non-internable string to a local const variable is cache-unfriendly in the current implementation of Lua: the constant string would exist as multiple copies in RAM and each copy would be cached independently.
I suggest to apply this optimization (to convert local const variables to real constants) only for internable strings.  Constant variables containing long strings should stay non-optimized in bytecode as if they were non-constant locals/upvalues.
static TString *loadStringN (LoadState *S, Proto *p) {
  lua_State *L = S->L;
  TString *ts;
  luaL_Buffer b;
  char *buff;
  size_t size = loadSize(S);
  if (size == 0)  /* no string? */
    return NULL;
  luaL_buffinit(L, &b);
  buff = luaL_prepbuffsize(b, size);
  loadVector(S, buff, size);  /* load string into buffer */
  ts = luaS_newlstr(L, buff, size);
  luaC_objbarrier(L, p, ts);
  return ts;

Ranier Vilela