Luau Bytecode EXPLAINED - How to Read, Debug, and Optimize Like a Hacker

This is not addressing any technical point I made.

Following me into unrelated threads to comment on my character instead of the topic is textbook ad hominem.

If you think something I said is incorrect, quote it and explain why. Otherwise this is just personal commentary, not discussion.

1 Like

How to make a bytecode interpreter for roblox

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.

2 Likes

Luau using a call stack does not make it a stack based VM.

1 Like

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.

2 Likes

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.

Please stop going off-topic; the discussion is about Bytecode and not Roblox-TS. Please stop pushing unrelated topics or attempting to harass me.

2 Likes

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.

3 Likes

Lacks a lot.

  1. 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
  2. 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.

2 Likes

There are 256 registers in total, but you only have access to 200, and I assume the other 56 are reserved for global imports and stack returns.