I understand that MicroPython, like CPython, is built around a stack-based virtual machine and corresponding bytecode. Have there been any thoughts about the alternative: a register-based VM (as used by, for example, recent versions of Lua [1])?
In general, the performance of register-based machines is better than stack-based ones. For example, a register-based Java interpreter was found to require 25-35% less time to execute benchmarks than a stack-based interpreter [2]. The downsides of this register-based VM were increased bytecode size (by 25%) and increased complexity of the compiler and VM.
However, a recent paper [3] describes a register-based bytecode which is smaller than the equivalent stack-based code, and concludes:
"Because of the advantages in speed and its small bytecode size, a register-based virtual machine can be best applied on systems where both computational and storage facilities are limited (e.g. embedded systems)"
Would it be possible to add a register-based bytecode to MicroPython, either as a configuration option or a replacement for the current stack-based bytecode? Do you think this would produce a significant increase in performance?
If so, has anybody worked on implementing such a bytecode? Is this a feature which MicroPython might have in the future, or is the performance increase not worth the added complexity?
[1] https://www.lua.org/doc/jucs05.pdf
[2] https://www.usenix.org/legacy/events/ve ... -yunhe.pdf
[3] https://arxiv.org/pdf/1611.00467v1.pdf
Register-based virtual machine?
Re: Register-based virtual machine?
On the other hand, stack-based bytecode is easier to generate, understand and debug. And the Python as a language has been created around a stack-based virtual machine precisely because of that. You could make a register-based machine, of course, but that wouldn't be Python anymore.
Re: Register-based virtual machine?
deshipu: "You could make a register-based machine, of course, but that wouldn't be Python anymore."
Are you saying that it would not be possible to use a register-based VM for Python (i.e. without changing the language)? I don't think that's true - for example, Dropbox's Pyston uses a register-based bytecode [1].
[1] http://blog.kevmod.com/2016/07/stack-vs ... or-python/
Are you saying that it would not be possible to use a register-based VM for Python (i.e. without changing the language)? I don't think that's true - for example, Dropbox's Pyston uses a register-based bytecode [1].
[1] http://blog.kevmod.com/2016/07/stack-vs ... or-python/
Re: Register-based virtual machine?
Both stack-based and vm-based approaches have equal computational power (both are turing-complete), so of course you can implement in one of them whatever you can implement in the other -- in the worst case, you can emulate one in the other. So it's clearly technically possible to implement Python on a register-based machine. In fact, that's actually what happens, if you look not just at the Python VM, but at the combo of the Python VM and your computer's CPU.
What I meant with my comment was rather that the Python as a language is specified in terms of a stack-based VM -- the definition of the language makes assumptions. I believe that a language that would have the same syntax and semantics on the surface, but translated that into different mechanisms underneath would be different enough to warrant calling it a new language. But then again, I don't consider MicroPython to be a real implementation of Python either.
What I meant with my comment was rather that the Python as a language is specified in terms of a stack-based VM -- the definition of the language makes assumptions. I believe that a language that would have the same syntax and semantics on the surface, but translated that into different mechanisms underneath would be different enough to warrant calling it a new language. But then again, I don't consider MicroPython to be a real implementation of Python either.