-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
collect arrays of objects prior to filling tuple in fixed-size conversions #3321
Conversation
e9b4afd
to
8939763
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the same thing for PyTuple::new (the variable sized constructor) with a Vec, but that worked out around 20% slower, so I haven't included that here for now.
While it is nice that this is an improvement, I think we should compare the cost of the above to the safe version using PyTuple_Pack
. We can either use the Vec
and PyTuple_New
or PyTuple_Pack
for the dynamically sized case.
8939763
to
6f30215
Compare
I haven't worked out how to use |
Ah, they chose a variadic interface which is not nice for composeability, c.f. https://c-faq.com/varargs/invvarargs.html I guess So I guess optimizing the common case using something like |
Yes, if someone is interested in trying this out it might be interesting. It sounds like there's some upstream debate on what the best API is so I'm inclined to leave as-is for now and let the dust settle. |
Replacement to #3296.
As discussed there, we believe it's safe to use
PyTuple_New
when there is confidence of no Python code running while filling the uninitialized tuple.Therefore in this PR I adjust the fixed-size conversions to collect into an array and then fill the tuple. I also happened to manage to optimize this by use of a const-generic helper which uses
PyTuple_SET_ITEM
(on the stable abi).Benchmark shows this is ~20% faster than
main
, and should be safer too:I tried the same thing for
PyTuple::new
(the variable sized constructor) with aVec
, but that worked out around 20% slower, so I haven't included that here for now.