This document introduces some ideas for future improvements.
Note that we don't want to work on most of these until we reach self-compilation.
Make it possible to define module-level constants. Potentially treat all-caps names as constants by default. Using an integer constant should have no performance penalty over an integer literal.
Implement basic optimizations such as common subexpression elimination and loop invariant code motion.
Some operations or combinations of successive operations can be replaced with more efficient operations. Examples:
-
If
s
is a string,s[i] == 'x'
doesn't need to construct the intermediate single-character string objects[i]
but just compare the character value toord('x')
. -
'a + ':' + b` (two string concetenations) can be implemented as single three-operand concatenation that doesn't construct an intermediate object.
-
x in {1, 3}
can be translated intox == 1 or x == 2
(more generally we need to evaluate all right-hand-side items).
Implement integer range analysis. This can be used in various ways:
- Use untagged representations for some registers.
- Use faster integer arithmetic operations for operations that only deal with short integers or that can't overflow.
- Remove redundant list and string index checks.
Make it possible to declare a class as final. Final classes don't support subclassing, and thus method calls don't need to go through a vtable.
Similar to final classes, make it possible to declare a method as final. Final methods can't be overridden (as far as mypyc can control it).
Somehow make it possible to enforce that attributes in a class are always defined. This makes attribute access faster since we don't need to explicitly check if the attribute is defined.