First of all, let me make it clear that I'm currently writing a bytecode interpreter.
I've been reading everywhere about the bytecode having to be "compact". However, I don't really understand what this is supposed to mean, or what the advantages would be.
Currently, for example, my "bytecode" is an array of tuples, the first element being a byte - the opcode itself (8 bits) and the second one a uint64 (what one would call an unsigned long long
) - the optional parameter for the operation (64 bits).
Tha makes each "instruction" 72 bits. (Admittedly quite innecessary, since many of them don't take any argument, but I thought it was easier - and more performant? - this way since I don't have to check every time if there is a parameter, and just go through the list of instructions).
So, my questions:
- what are the benefits of a more compact code? (what would I achieve if, for example, each instruction was 32 bits instead of 72?)
- what could I do to make it better? (how do I handle "optional" arguments in an efficient way? that is: variable-sized instructions)