Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-129149: Add fast paths to four morePyLong_From* functions#131211

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
picnixz merged 4 commits intopython:mainfromchris-eibl:more_pylong_from
Mar 30, 2025

Conversation

@chris-eibl
Copy link
Member

@chris-eiblchris-eibl commentedMar 13, 2025
edited by bedevere-appbot
Loading

Use the macroPYLONG_FROM_INT to implementPyLong_FromInt32() andPyLong_FromInt64(), and the macroPYLONG_FROM_UINT to implementPyLong_FromUInt32() andPyLong_FromUInt64(), because they have a fast path for small and medium-size integers.

before:

PyLong_FromInt32: some small ints          -5:   228.22 ms           0:   218.91 ms         256:   214.52 msPyLong_FromInt32: some medium ints -1073741823:   313.45 ms        1000:   196.13 ms  1073741822:   305.81 msPyLong_FromInt32: some bigger ints -1073741824:   305.89 ms  1073741824:   283.47 ms

after:

PyLong_FromInt32: some small ints          -5:    21.09 ms           0:    20.80 ms         256:    20.27 msPyLong_FromInt32: some medium ints -1073741823:   100.03 ms        1000:   101.13 ms  1073741822:    98.36 msPyLong_FromInt32: some bigger ints -1073741824:   204.82 ms  1073741824:   205.22 ms

Benchmark done like in#129301 (comment).

@chris-eiblchris-eibl changed the titleGH-129149: Add fast path for small and medium-size integers inPyLong_FromInt32(),PyLong_FromInt64(),PyLong_FromUInt32() andPyLong_FromUInt64()GH-129149: Add fast paths to four morePyLong_From* functionsMar 13, 2025
@picnixzpicnixz self-requested a reviewMarch 13, 2025 20:40
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Are the tests also updated accordingly? (namely do they correctly test all paths?)

@chris-eibl
Copy link
MemberAuthor

Pretty much the same astest_long_as_ssize_t we've discussed in#129301: via round tripping e.g. for inPyLong_FromUInt32

staticPyObject*
pylong_asuint32(PyObject*module,PyObject*arg)
{
NULLABLE(arg);
uint32_tvalue;
if (PyLong_AsUInt32(arg,&value)<0) {
returnNULL;
}
returnPyLong_FromUInt32(value);
}

and then usingcheck_long_asint, where I've already added more values to cover more cases (especially negative small and medium-size integers):#129301 (comment)

@chris-eibl
Copy link
MemberAuthor

Maybe add even more values? Definitely no performance bottleneck and might gain test coverage. E.g. one more positive and negative small integer?

@picnixz
Copy link
Member

Maybe add even more values? Definitely no performance bottleneck and might gain test coverage. E.g. one more positive and negative small integer?

If we're already covering the small, medium and large integers, both in negative and positive ranges, it's fine.

chris-eibl reacted with thumbs up emoji

@chris-eibl
Copy link
MemberAuthor

@vstinner are you fine with this? (sorry for the ping, though)

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@picnixzpicnixz self-assigned thisMar 29, 2025
@picnixzpicnixz merged commita175d64 intopython:mainMar 30, 2025
46 checks passed
@picnixz
Copy link
Member

Thank you!

chris-eibl reacted with laugh emoji

@chris-eiblchris-eibl deleted the more_pylong_from branchMarch 30, 2025 08:41
seehwan pushed a commit to seehwan/cpython that referenced this pull requestApr 16, 2025
…rom*` functions (python#131211)Add a fast path for medium-sized integers in `PyLong_FromInt{32,64}` and `PyLong_FromUInt{32,64}`.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner approved these changes

@picnixzpicnixzpicnixz approved these changes

Assignees

@picnixzpicnixz

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@chris-eibl@picnixz@vstinner

[8]ページ先頭

©2009-2025 Movatter.jp