cpython icon indicating copy to clipboard operation
cpython copied to clipboard

bpo-33092: Better bytecodes for f-strings

Open markshannon opened this issue 7 years ago • 2 comments

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

markshannon avatar Mar 17 '18 13:03 markshannon

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.

alimcmaster1 avatar Apr 11 '20 00:04 alimcmaster1

This PR is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 16 '22 00:08 github-actions[bot]

CC: @rhettinger @ambv

furkanonder avatar May 11 '23 15:05 furkanonder

Updated to use the new bytecode definition format.

Removes the conditional stack effect, simplifying tooling around these instructions.

markshannon avatar Jun 08 '23 11:06 markshannon

Looks like you missed out the doc update.

iritkatriel avatar Jun 08 '23 12:06 iritkatriel

https://github.com/python/cpython/issues/105678

markshannon avatar Jun 12 '23 09:06 markshannon