bpo-33092: Better bytecodes for f-strings
Simplify and speed up interpreter for f-strings.
tldr; Do work in the compiler instead of the interpreter.
Splits the FORMAT_VALUE opcode into CONVERT_VALUE, FORMAT_SIMPLE and FORMAT_WITH_SPEC. The compiler can then emit the optimal sequence for each format expression.
The three new opcodes are much simpler than the one they replace, actually removing a few lines of code from the interpreter.
The CONVERT_VALUE is emitted only if a conversion is present. In the standard library only (approx) 20% of f-strings include a conversion.
FORMAT_WITH_SPEC is emitted if a format specifier is present. Otherwise FORMAT_SIMPLE is emitted. In the standard library about 70% of format expressions can be formatted with just the simple (and fast) FORMAT_SIMPLE opcode.
https://bugs.python.org/issue33092
Any update on this @taleinat suggested sharing benchmarks here https://bugs.python.org/issue33092.
Otherwise due to lack of activity I think we can close this.
This PR is stale because it has been open for 30 days with no activity.
CC: @rhettinger @ambv
Updated to use the new bytecode definition format.
Removes the conditional stack effect, simplifying tooling around these instructions.
Looks like you missed out the doc update.
https://github.com/python/cpython/issues/105678