-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-127936: convert marshal module to use import/export API for ints (PEP 757) #128530
gh-127936: convert marshal module to use import/export API for ints (PEP 757) #128530
Conversation
1ab0c30
to
4bd6b0c
Compare
CC @vstinner I suspect that major slowdown for marshal.loads() benchmarks is due to normalization&singletonization in the PyLongWriter_Finish(). In case of marshal.dumps() I suspect things were better without the |
Co-authored-by: Victor Stinner <vstinner@python.org>
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.
LGTM. I'm (just) a bit unfortunate that the using PEP 757 makes the code slower.
@serhiy-storchaka @picnixz: Would you mind to review this change?
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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.
A couple of assertions to add and we're good I think. The most important assertion is assert(layout->bits_per_digit >= PyLong_MARSHAL_SHIFT);
because marshal_ratio
is 0 otherwise.
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 would still appreciate an assert on any T
that does digits[T - 1]
for those who only read the macros (or for reviewers) even though you're asserting that at the caller site. The assertions cost nothing and it's semantically better to have assertions verified once you've called the function before calling it (for debugging it's easier to put them before the call so that you know which caller was the bad caller, however I think that assertions should be logically placed in the callee; thus I would put them at both places).
Now, I won't block on this nitpick since it's a matter of taste.
Of course, assert's costs nothing, but I doubt we need this redundancy. Macros code not too big to see obvious assumptions on n/size arguments. So, I'll add suggestions and postpone decision to other reviewers. |
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@skirpichev: Can you just add |
While the code is obvious to you, assertions can help reviewers, who are not used to the code, to understand it. It's not only to check for correctness at runtime. |
Done. Feel free just to edit my pr/suggestions in similar cases.
Well, just the next "for" line, IMO, revival code assumptions for most code readers. |
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Merged. Congrats @skirpichev, this one was tricky :-) |
Benchmark hidden because not significant (1): dumps 1<<7
scripts