Repository navigation
The bytecode for f-string formatting is inefficient. #77273
Description
Activity
f-string expressions can be formatted in four ways:
with or without a conversion
and
with or without a format specifierRather than have one bytecode that parses the opcode argument at runtime it would be more efficient and produce a cleaner interpreter for the compiler to produce one or two bytecode as required.
The bytecodes should be:
CONVERT_VALUE convert_fn
FORMAT_SIMPLE
FORMAT_WITH_SPECFor simple format expressions with no conversion or format specifier,
which make up about 3/4 of all format expressions in the standard library, just the bytecode FORMAT_SIMPLE need be executed.- added3.8 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
on Mar 17, 2018 Would this change really have a performance impact? Not saying it wouldn't, but if we're going to add bytecodes we should know the answer in advance.
Even if doesn't speed things up by a significant amount, I would suggest that a simper interpreter with smaller, simpler bytecodes is a worthy goal in itself.
I would suggest that a simper interpreter with smaller, simpler bytecodes is a worthy goal in itself.
+1 from me. Though I'm curious about performance changes as well :-)
I wouldn't say this more efficient. Instead one instruction you would need to execute two instructions.
If I implemented f-string formatting I would add four simple opcodes for str(), repr(), ascii() and format(). But Eric merged them all in the single opcode with complex argument. While this looks more complicated and less extensible, it is more efficient.
Mark, since you have a working version of this, perhaps you can supply some performance benchmark results to help in making a decision?
No significant change in performance https://gist.github.com/markshannon/34a780d65e69b5a573a83f3fdb0139aa
I think this merely indicates that there are little to no f-strings in the pyperformance benchmark suite.
- added3.12only security fixesonly security fixesand removed3.8 (EOL)end of lifeend of life
on Sep 1, 2022 @markshannon are you still interested in this? should we repeat the measurements with benchmarks that have more f-strings?
- added a commit that references this issue
on Jun 14, 2023 - added a commit that references this issue
on Jun 15, 2023 Looks like this was implemented in #6132, thanks all!
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: