The Viper code emitter
“Viper” gibt es scheinbar weiterhin und findet sich gerade auch beim Vanilla MicroPython als nativer code emitter ein – zumindest wird es hier in den vorletzten MicroPython 1.10 release notes häufig erwähnt. Das hat mit dem ursprünglichen “Viper”, aus dem Zerynth hervorgegangen ist, vermutlich überhaupt nichts zu tun.
Auch MicroPython für den ESP8266 hat einen nativen Code Emitter, siehe esp.set_native_code_location for ESP8266 .
Historie
Der optimierende Viper native code emitter wurde erstmals 2013 von Damien George erwähnt.
https://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers/posts/664832
[…] explain a bit about the 3 different Python code emitters: byte code, native code, and native code with native types. The third type I call “viper” for short (after the snake). There is a fourth type, inline assembler, that I will discuss in a following update.
This discussion is a little technical and I don’t want to scare you in to thinking that you need to understand any of it. You don’t! Micro Python is designed to be easy for the beginner to get starting doing cool stuff right away. But it also has some sophisticated features for when you need them.
Weitere Diskussionen
shakna on Feb 7, 2018 | on: Python’s Weak Performance Matters
Viper is an interesting approach on speeding up Python.
It’s developed for MicroPython, which does give them room for breaking changes, but has trade-offs.
Arithmetic is much faster, but dictionary lookups take much longer compared to CPython.
Viper is a code-emitter from a large subset of Python, and even allows for inline assembly. But it’s only for a few architectures at the moment, like ARM and x86.
cromat3 on Feb 7, 2018
Viper is called Zerynth today: Zerynth - Python Wiki
shakna on Feb 7, 2018
They’re similar, but not the same.
Zerynth is a development suite. Notably, it makes use of a VM.
Viper is just one of the code emitters buried inside the MicroPython source code, like here [0]. Notably, it produces native code, not bytecode for a VM.
[0] micropython/py/objfun.c at master · micropython/micropython · GitHub
How fast is MicroPython?
Rett Berg and Paul Sokolovsky:
We try to make MicroPython have about same, or better, average performance as CPython, while offering considerably smaller memory footprint (both code (“ROM”) and heap (“RAM”) sizes). Optimizing for size is known to be opposite of optimizing for speed, so in some cases MicroPython may be slower (an example is diversified access to large dictionaries). However, on some operations (like integer arithmetics), MicroPython can be around 10 times faster than CPython 3.3 (note that CPython itself is being optimized, so newer versions may be faster than older).
Additionally, on select architectures (which include the most popular ones like x86, x86_64, ARMv7), MicroPython offers an ahead-of-time compiler for large subset of Python language, which may increase performance 2 times on average. Beyond that, MicroPython offers “viper” native compiler for a smaller subset of Python language, which offers near-C speed for arithmetic/memory operations. As a final touch, MicroPython offers inline assembler support (currently only for ARMv7 (Thumb2)), for really performance-critical code.
Summing up, MicroPython offers wide selection of performance options and optimizations, allowing you to get the performance you need - all available even on a microcontroller!
– FAQ · micropython/micropython Wiki · GitHub
If you are looking into how things could be sped up further, Just-in-Time (JIT) compilation might come to MicroPython at some time in the future.