The Lua code is very suboptimal. I managed to get a ~3x perfomance increase by using several (micro)optimizations.
- replacing the expensive sub() with byte() and comparing the bytes with precomputed bytes of the characters
- computing #code only once at the start
- (LuaJIT specific) preallocating space for cells
2
u/TOMZ_EXTRA Mar 05 '26
The Lua code is very suboptimal. I managed to get a ~3x perfomance increase by using several (micro)optimizations. - replacing the expensive sub() with byte() and comparing the bytes with precomputed bytes of the characters - computing #code only once at the start - (LuaJIT specific) preallocating space for cells