Uh oh!
There was an error while loading. Please reload this page.
gh-116738: Inline append for local PyList - #135196
Conversation
Uh oh!
There was an error while loading. Please reload this page.
mpage
commented
Jun 6, 2025
Can you add a sentence or two about the motivation for this change (performance?) to the PR description? |
yoney
commented
Jun 10, 2025
Updated the description, thank you! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Yhg1s
left a comment
There was a problem hiding this comment.
I'm a little skeptical that the performance is ever going to matter (getgrall() is unlikely to be very big and if it is, it's always going to be horrendously slow) but the code is clear enough and the assert protects us against unintended sharing of the list, so why not.
| struct group *p; | ||
| // `d` is a local list; append items without a lock using | ||
| // _PyList_AppendTakeRef() within the loop. | ||
| assert(_PyObject_IsUniquelyReferenced(d)); |
There was a problem hiding this comment.
d is not passed anywhere, isn't this obvious? we never added such assertions where it was obvious like this case
kumaraditya303
commented
Jun 11, 2025
I doubt that getgrall would produce so many entries to that performance of this would matter, using private API even in non core extension modules and non performance critical code seems like a bad idea to me so -1 from me. |
yoney
commented
Jun 11, 2025
@Yhg1s, @kumaraditya303: Thank you for the reviews. I completely agree that performance is very unlikely to matter here for @kumaraditya303 As far as I understand, you prefer to use the private API only when the performance wins can be clearly measured. @Yhg1s@kumaraditya303, I could close the PR and, in the future, make changes only when the performance benefits of using private APIs are clearly measurable. What do you think? |
kumaraditya303
commented
Jun 12, 2025
Yes, that sounds better |
Yhg1s
commented
Jun 12, 2025
Yes, I think that's the right approach in this. (Your efforts are nonetheless appreciated, Alper :) |
Append items to the local list in a loop without a lock.
Appending to the list without a lock can improve performance, but testing
grp.getgrall()produced noisy results, making it difficult to determine any improvement. Running a micro benchmark with a function that adds over 100K items to the list using_PyList_AppendTakeRef()instead ofPyList_Append()showed about a 35% performance improvement.cc: @mpage@colesbury