Repository navigation
gh-160147: Optimize make_new_set_untracked() - #161191
Conversation
There is no need to set PySetObject explicitly to 0/NULL, since _PyType_AllocNoTrack() already initialize memory to zeros.
eendebakpt
left a comment
There was a problem hiding this comment.
Changes are correct. I checked and the compiler does not optimize it away (because type is not compile time), so this is a minor optimization. Did you do benchmarks victor?
I am wondering if we should do this more (there are dozens of sites in cpython where this can be done, some hot paths are enumerate and BaseException_new).
No, I didn't, but I can run a micro-benchmark: Benchmark: Result: In fact, if I rerun the benchmark... I get the opposite result: So it's hard to measure the benefits of this change, it's lost in the benchmark noise. x86-64 assembly code, before: there are multiple instructions to set members to zero, like Detailsx86-64 assembly code, after: the code is 23 bytes smaller (124 => 101 bytes), the instructions to set members to zero are gone. Details |
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
I'm not sure that it's worth it to update all constructions setting members to It's just that I'm modifying setobject.c code, and I spotted this missed optimization opportunity. |
There is no need to set PySetObject explicitly to 0/NULL, since _PyType_AllocNoTrack() already initialize memory to zeros.
PyFrozenWriterC API to create afrozensetobject #160147