mjanicek / rembulan

Rembulan, an implementation of Lua 5.3 for the Java Virtual Machine
Apache License 2.0
163 stars 28 forks source link

Avoid unnecessary boxing and unboxing in the generated code #13

Open mjanicek opened 8 years ago

mjanicek commented 8 years ago

The compiler currently requires all local and temporary variables to be boxed. This introduces a significant performance penalty.

For instance, in the following snippet:

local x = 0
for i = 1, 10 do
  x = x + i
end

every arithmetic operation with x or i involves unboxing it, performing the operation, and boxing the result again. Boxing here is not necessary: it can be determined statically that x is and i are integers, so they can be replaced with primitives while maintaining semantics.

How to go about this

The required static type analysis is already in place. The only remaining thing to do is to change the layout of the generated code to support unboxed local variables and temporaries, and wire the operations up accordingly.