The luau compiler is dumb mainly because the compiler has to work around the fact that luau is dynamically typed and anything can have a random metatable overriding operators. Many trivial optimizations that would barely impact compilation time are not performed for this reason.
This looks like a very fine post, but I would argue that most optimizations fail, because it’s hard to picture a tree (not literally before any of the literals come here).
Thank you very much for bringing this into my perspective. It’s actually very insane to say that hardcoded codebase is optimized, but it’s true. This is unless we have some sort of a transpiler that embeds.
Hey. Actually, we have this in Roblox-TS with const enums. This is why you should give Roblox-TS a try.
That’s just common sense; think in systems, not bananas.
The topic is about bytecode; please stop pushing/advertising Roblox-TS in entirely unrelated discussions, and, moreover, code produced by Roblox-TS is horrendous.
Furthermore, I am not advertising Roblox-TS nor was I paid to. I am sharing resource I know out of selflessness. There is a better way to work closely to the logic of Luau bytecode, and that is Roblox-Typescript, especially with const enums which allows you to add configurable values without adding extra work onto the bytecode in runtime. This is related whether you disagree or not, and I’m so sorry to hear that you are quite upset with this. It is unfortunate, but this is part of the conversational exchange.
The purpose of the post is to understand Luau bytecode, so you can optimize the game. A developer that keeps up with industry standard does not reject discoveries and tries to fit it in their workspace. I am not saying you shouldn’t learn Luau bytecode. I am saying Roblox-TS works with Luau bytecode, because Roblox-TS transforms its code into Luau and it allows you to optimized while staying flexible. Luau does not serve const enums or configurable hardcoding before runtime.
this is one of the dumbest things i have ever read. it does add extra work onto the bytecode on runtime, have you seen the transpiled roblox-ts code. and the best way to get close to the logic of luau bytecode is to write luau without metatables. simple.
One nuance worth mentioning is that the bytecode isn’t always the exact execution path. Some instructions (especially FASTCALL sequences and imports) are internally specialized by the VM, so what we see in the disassembly is more of a logical IR rather than the exact runtime path for hot calls
Register pressure can affect compiler output, Luau’s register VM means too many locals can actually change generated bytecode.
FASTCALL calls a built-in function using an index into a function table. It is effectively a nested instruction dispatch. The rest of the sequence is a fallback for when the fast call fails. So there isn’t any extra internal specialization going on.
If you have too many locals, your code will not compile. That’s why there is a local limit.