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: [easy C] long type performance waste in 64-bit Windows build
Type: performance Stage:
Components: Windows Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: malin, paul.moore, serhiy.storchaka, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2020-11-10 07:33 by malin, last changed 2022-04-11 14:59 by admin.

Messages (6)
msg380638 - (view) Author: Ma Lin (malin) * Date: 2020-11-10 07:33
C type `long` is 4-byte integer in 64-bit Windows build (MSVC behavior). [1]
In other compilers, `long` is 8-byte integer in 64-bit build.

This leads to a bit unnecessary performance waste, issue38252 fixed this problem in a situation.

Search `SIZEOF_LONG` in CPython code, there's still a few long type waste.

Novices are welcome to try contribution.

[1] https://stackoverflow.com/questions/384502
msg380642 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-11-10 09:41
What is the problem exactly?
msg380644 - (view) Author: Ma Lin (malin) * Date: 2020-11-10 09:54
> What is the problem exactly?

There are several different problems, such as:
https://github.com/python/cpython/blob/v3.10.0a2/Modules/mathmodule.c#L2033

In addition, `utf16_decode` also has this problem, I forgot this:
https://github.com/python/cpython/blob/v3.10.0a2/Objects/stringlib/codecs.h#L465

Maybe these small problems are suitable for newcomer to familiarize the contribution process.
msg380646 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-11-10 10:08
I do not think that this is suitable for newcomers because you need to have deep understanding why it was written in such form at first place and what will be changed if you change it.

The code was written when unsigned long long was not standard and 64-bit integer type was not required in Python. PyLong_FromUnsignedLongLong could just not exist on the particular platform. Using long long optionally would complicate the code, and it was not always justified. And it could negatively affect performance, especially on 32-bit platforms.
msg380647 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-10 10:19
> There are several different problems, such as:
> https://github.com/python/cpython/blob/v3.10.0a2/Modules/mathmodule.c#L2033

I don't think that it's worth it to optimize this one.

> In addition, `utf16_decode` also has this problem, I forgot this:
https://github.com/python/cpython/blob/v3.10.0a2/Objects/stringlib/codecs.h#L465

I suggest to fix in it bpo-38252.
msg380649 - (view) Author: Ma Lin (malin) * Date: 2020-11-10 10:33
> I do not think that this is suitable for newcomers because you need to have deep understanding why it was written in such form at first place and what will be changed if you change it.

I agree contributors need to understand code, rather than simply replace the type. Maybe two weeks is enough to understand the code.

> And it could negatively affect performance, especially on 32-bit platforms.

`long` type can be replaced by `ssize_t`.
`unsigned long` type can be replaced by `size_t`.
And use `PyLong_FromSize_t`/`PyLong_FromSize_t`, then there is no negative impact.

> I don't think that it's worth it to optimize this one.

Although the speedup is small, it's free.
I don't see it as optimization, just no more waste.

> I suggest to fix in it bpo-38252.

I forgot it in that issue, I just searched "0x80808080" in the code, it was missed.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86470
2020-11-10 10:33:09malinsetmessages: + msg380649
2020-11-10 10:19:21vstinnersetnosy: + vstinner
messages: + msg380647
2020-11-10 10:08:21serhiy.storchakasetmessages: + msg380646
2020-11-10 09:54:46malinsetmessages: + msg380644
2020-11-10 09:41:51serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg380642
2020-11-10 07:33:14malincreate