This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add PyType_FastSubclass for float
Type: Stage: resolved
Components: C API Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: mattip, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-12-19 10:38 by mattip, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30200 merged mattip, 2021-12-19 10:57
PR 30208 merged rhettinger, 2021-12-19 20:26
Messages (8)
msg408890 - (view) Author: mattip (mattip) * Date: 2021-12-19 10:38
The basic classes int, dict, list, tuple ... all have a fast path for Py_*Check(obj):

#define PyLong_Check(op) \
        PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)


except for float. I propose to add a Py_TPFLAGS_FLOAT_SUBCLASS enum and use it to implement PyType_FastSubclass for float.
msg408891 - (view) Author: mattip (mattip) * Date: 2021-12-19 10:55
"complex" is also missing a fast path
msg408896 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-19 12:51
It is because PyFloat_Check() and PyComplex_Check() are rarely used in comparison with checks for integers, strings, etc. The flags space is limited, so it is better to use it for something more important.

There were reasons for not adding such flags at first place and I think that they are still valid.
msg408923 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 20:24
Thanks for the suggestion, but I also concur with Serhiy.
msg408924 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 20:24
New changeset 2ef06d412531d1163dbc72877c88aedf3ed82a25 by Matti Picus in branch 'main':
bpo-46131: add fastpath for PyFloat_Check() (#30200)
https://github.com/python/cpython/commit/2ef06d412531d1163dbc72877c88aedf3ed82a25
msg408925 - (view) Author: mattip (mattip) * Date: 2021-12-19 20:53
What do ya'all think of widen the flags field to int64_t so that there is more room for optimizations like this?
msg408926 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 21:05
New changeset 29ea68bd1dcf30842c2ed908a6d815bc1d90f484 by Raymond Hettinger in branch 'main':
Revert "bpo-46131: add fastpath for PyFloat_Check() (GH-30200)" (GH-30208)
https://github.com/python/cpython/commit/29ea68bd1dcf30842c2ed908a6d815bc1d90f484
msg408927 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 21:07
That would not change that slot space is at a premium and that we prefer to use that space for high payoff optimizations.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90289
2021-12-19 21:07:50rhettingersetmessages: + msg408927
2021-12-19 21:05:54rhettingersetmessages: + msg408926
2021-12-19 20:53:03mattipsetmessages: + msg408925
2021-12-19 20:26:42rhettingersetpull_requests: + pull_request28429
2021-12-19 20:24:38rhettingersetmessages: + msg408924
2021-12-19 20:24:14rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg408923

resolution: rejected
stage: patch review -> resolved
2021-12-19 12:51:36serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg408896
2021-12-19 10:57:57mattipsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28421
2021-12-19 10:55:06mattipsetmessages: + msg408891
2021-12-19 10:38:20mattipcreate