-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-144380: Fix incorrect type check in buffered_iternext()
#144381
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
gh-144380: Fix incorrect type check in buffered_iternext()
#144381
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Thanks for catching this. Would you please add a news entry (blurb)? |
The condition used Py_IS_TYPE(tp, ...) where tp is already a `type`, this made the fast path unreachable. Avoid unnecessary method resolution checks in the iteration hot path, resulting in ~49% faster line iteration for `io.BufferedReader`.
6230d1a to
257b345
Compare
Thanks, new entry added |
|
Thanks @ruiyangke for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…ythonGH-144381) (cherry picked from commit 40d07cad38bf3ce60f4ca03f1836e8650fe40df5) Co-authored-by: Ruiyang Ke <me@ry.ke>
…ythonGH-144381) (cherry picked from commit 40d07ca) Co-authored-by: Ruiyang Ke <me@ry.ke>
|
GH-144389 is a backport of this pull request to the 3.14 branch. |
|
GH-144390 is a backport of this pull request to the 3.13 branch. |
|
Fix incorrect type check in
buffered_iternext()that prevented the fast path from ever being taken, slowing down iteration over buffered binary files.Since
tpis already a type object,Py_IS_TYPE(tp, X)expands toPy_TYPE(tp) == X, which compares thetypeitself againstBufferedReader. This is always false, so the fast path was never taken.pyperf benchmark:
Closes: #144380
buffered_iternextis never taken due to incorrect type check #144380