bpo-45636: Remove the old %-formatting fast-path#29532
bpo-45636: Remove the old %-formatting fast-path#29532brandtbucher merged 5 commits intopython:mainfrom
%-formatting fast-path#29532Conversation
|
Do you have any evidence that adding As a general comment, avoid |
|
Just be clear. |
Yep, your intuition seems correct here. Removing both the specialization and the fast path has no impact on I was curious, so I also ran a few micro-benchmarks on PGO/LTO builds. This benchmark tests basically the simplest possible case of string formatting (
It looks like optimizing this has negligible improvement (if any). I'm comfortable removing it, especially since more generic operator implementation caching will likely benefit this case anyways. |
| SpecializedCacheEntry *cache) | ||
| { | ||
| _PyAdaptiveEntry *adaptive = &cache->adaptive; | ||
| if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) { |
There was a problem hiding this comment.
I want to keep this change, though (it allows us to "un-adapt" more instructions in the default case).
%-formatting optimization
%-formatting optimization%-formatting fast-path
|
FWIW, nearly 13 years ago this showed a modest improvement. I'm not surprised it no longer does, I just got curious why we had this optimization in the first place: https://bugs.python.org/issue5176 8725dce |
Maybe because of Serhiy's work in https://bugs.python.org/issue28307. That should cover most common use cases. |
|
Oh, but that means that Brandt's micro-benchmark doesn't show the effect. |
|
Did you try at least a micro-benchmark that doesn't generate code from the format string? (Not that it would matter, it's a rare use case, but it would seem useful to at least know.) |
My micro-benchmark doesn't hit Serhiy's AST optimization. That only kicks in when the LHS is a string literal and the RHS is a tuple display, I think: >>> dis.dis('l, r = "%s", ""; l % r')
1 0 LOAD_CONST 0 (('%s', ''))
2 UNPACK_SEQUENCE 2
4 STORE_NAME 0 (l)
6 STORE_NAME 1 (r)
8 LOAD_NAME 0 (l)
10 LOAD_NAME 1 (r)
12 BINARY_OP 6 (%)
14 POP_TOP
16 LOAD_CONST 1 (None)
18 RETURN_VALUE |
No perf impact:
Details
https://bugs.python.org/issue45636