-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-45636: Remove the old %
-formatting fast-path
#29532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
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. |
@@ -1380,13 +1380,13 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, | |||
SpecializedCacheEntry *cache) | |||
{ | |||
_PyAdaptiveEntry *adaptive = &cache->adaptive; | |||
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
https://bugs.python.org/issue45636