bpo-46254: Better fitting type for iterating in the trace_init C function.#30394
bpo-46254: Better fitting type for iterating in the trace_init C function.#30394UriyaHarpeness wants to merge 1 commit into
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
JelleZijlstra
left a comment
There was a problem hiding this comment.
What is the motivation for this change?
int is a more idiomatic type, and chances are it doesn't affect the compiled code either way.
I want Python to be the best it can possibly be, meaning also using the most fitting types, I would want to open a following PR doing the same fitting for more place in the file |
|
Sorry, I'm not convinced. In a product as widely used as CPython, we shouldn't change anything unless it's a clear improvement, since there's always a risk that it will unexpectedly break something. For this change, is it a common recommendation for C code (e.g., in widely used style guides) to avoid an int type if you only use values that fit in a smaller type? Does it actually affect the code output by the compiler? |
There is a slight change in the resulting binary (makes it a little bit smaller), it's not like the compiler optimizes the types in C. Same reason that one would prefer holding a small number of unique values in a The reason I want to change this code is because I stumbled on this C implementation while reading about Python tracing, and it was just so weird to me that although I'm not a Python master, I could see this wrong type very easily, and if there is a chance for me to make CPython a little bit better, I would do it. |
Do you evidence/a reference for this? |
I have tried it, and it reduces the size of the function containing that type and loop, though it may not always change the final binary size because of size alignments. |
On which compiler/system? We don’t commit changes without proper discussion, including sharing our evidence (in a reproducible way). The place for that is the issue on the bug tracker rather than the PR. Many ‘obvious’ optimisations don’t work out in practice. |
|
But the propose of the PR isn't binary changes, it's using a more correct type, doesn't matter if it adds or removes 4 bytes from the whole python executable. |
|
Thank you for volunteering to improve python. As I said in my previous message, we discuss changes on the bug tracker (more contentious or significant changes in the mailing lists). The discussion on the PR is for code review - discussing details of the implementation. Cosmetic changes to the code are rarely approved when they don’t bring a demonstrable benefit. On this bases I am going to reject this change. I would suggest that you try to contribute by resolving issues reported on the bug tracker. Begin with the ones labelled ‘easy’. |
|
I get that this PR isn't necessary to improve runtime or anything really critical, but I don't understand why cosmetic changes are rejected. The code could be improved with this small PR... Even if this PR is closed and will not be merged, I don't understand the reason to reject cosmetic changes. |
There are two reasons:
|
|
OK, thank you @iritkatriel, I hope to contribute in the future with something that would be merged. |
|
I got curious and tried it on the https://godbolt.org/ compiler explorer. The assembly is slightly different with no compiler options, because the variable is on the stack and the compiler uses a differently sized Compilable code sample used: Details |


https://bugs.python.org/issue46254