RPython
Created on 2020-08-20T05:48:26.883036
- RPython is a subset of Python which can be transpiled to C.
- RPython can also be run in Python, or rather, can run itself after being compiled.
- Other interpreters written in RPython can also compile themselves, then run in their own interpreters which collect profiling data.
- JITs are made for languages by way of adding begin and end fences. The RPython framework can then decide if these barriers are triggered often enough to optimize. If so they "trace" opcodes that get run between the start and end fences to create machine code for this specific path.
- "Meta-tracing JIT" means the JIT does not have to be manually written. It is generated by creating traces of what the bytecode interpreter actually does.
- Traces are run through special "trace optimizers" that simplify a linear stream of code with known data.
- Optimizing for the trace optimizer: adjusting how the interpreter works to fit with optimization passes your trace optimizer knows how to do. In the paper they use variable length lists as an example; switching to fixed size lists or linked lists allows the optimizer to make more assumptions and so it creates more of the optimized JITs for you.
- Avoidance of dispatch overhead by pre-caching method dispatches and adding fences (guards) to ensure the object still meets expectations.
- Compiling the RPython base system can take up to an hour.
- RPython takes more time to "warm up" because it has layers of tracing generators involved.
An informal study of real systems showed that most objects have 5 or fewer slots.
TODO thoughts on combining a method compiler (like Exupery) with trace compilers, perhaps using a bandit algorithm to determine when to trace, when to method compile and when to fall back to interpreting.