3 ms·
One example of when goto is a good idea. Why is Lua 5.2 so much faster than Lua 5.1? Lua 5.2 supports a new goto keyword. This is incredibly useful when doing
by killahpriest 14y ago
One example of when goto is a good idea.
Why is Lua 5.2 so much faster than Lua 5.1? Lua 5.2 supports a new goto keyword. This is incredibly useful when doing this kind of compilation as it allows me to pass execution directly from basic block to basic block. Lua 5.1 doesn't have this, which means I have to fake goto using what boils down to a switch statement. This is much less efficient.
- Dylan16807 14y agoLooking at the source "boils down to a switch statement" appears to be a chain of ifs. It makes me wonder how fast it would have been to use tail calls. Also possibly worth noting is that lua 5.1 bytecode has gotos, if you're willing to step down a level.
- david-given 14y agoClue 0.3 did precisely that. Unfortunately it required a patched Lua to produce the special bytecode. I decided that that was cheating --- plus it meant the Lua backend wouldn't generate code for LuaJIT. Changing it to generate tail calls would be an excellent idea, but to do it right would require a major rewrite of the backend (most of the code generator is common code).
- gngeal 14y agoLua 5.1 doesn't have this, which means I have to fake goto using what boils down to a switch statement. This is much less efficient. Or he could just use tail calls and be done with it. I mean, that's the reason why the tail calls are there in the first place.