Skip to content
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

Missing fast path in PyLong_From*() functions for compact integers #129149

Closed
chris-eibl opened this issue Jan 21, 2025 · 1 comment
Closed

Missing fast path in PyLong_From*() functions for compact integers #129149

chris-eibl opened this issue Jan 21, 2025 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-feature A feature request or enhancement

Comments

@chris-eibl
Copy link
Contributor

chris-eibl commented Jan 21, 2025

Feature or enhancement

Proposal:

See e.g. the fast path using_PyLong_FromMedium() in PyLong_FromLong(). PyLong_FromLongLong() is almost identical.

Maybe then implement PyLong_FromSsize_t(), PyLong_FromLong() and PyLong_FromLongLong()) using a macro similar to PYLONG_FROM_UINT to get rid of the repetitive code?

PYLONG_FROM_UINT is missing the fast path for medium values, too.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

Per encouragement from @iritkatriel in #128927 (comment)

Linked PRs

@chris-eibl chris-eibl added the type-feature A feature request or enhancement label Jan 21, 2025
@picnixz picnixz added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jan 21, 2025
@picnixz picnixz changed the title PyLong_FromSsize_t(), PyLong_FromUnsignedLong(), PyLong_FromUnsignedLong() and PyLong_FromSize_t() miss the fast path for compact integers Missing fast path in PyLong_From*() functions for compact integers Jan 21, 2025
@chris-eibl
Copy link
Contributor Author

chris-eibl commented Jan 21, 2025

PyLong_FromInt32(), PyLong_FromUInt32(), PyLong_FromInt64 and PyLong_FromUInt64() could maybe use these macros, too.
They do "the same thing" in a totally different way ...
PR is here #131211, and would also give us some nicely speed ups.

vstinner added a commit that referenced this issue Jan 23, 2025
…rs (#129168)

Add fast path in PyLong_From*() functions for compact integers.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
chris-eibl added a commit to chris-eibl/cpython that referenced this issue Jan 25, 2025
Use it in PyLong_FromLong() and PyLong_FromLongLong().
This is just a refactoring and will create the same binary code.
skirpichev added a commit to chris-eibl/cpython that referenced this issue Jan 26, 2025
chris-eibl added a commit to chris-eibl/cpython that referenced this issue Jan 29, 2025
chris-eibl added a commit to chris-eibl/cpython that referenced this issue Mar 1, 2025
chris-eibl added a commit to chris-eibl/cpython that referenced this issue Mar 12, 2025
picnixz pushed a commit that referenced this issue Mar 13, 2025
…ze_t()` (#129301)

The implementation of `PyLong_FromLong()`, `PyLong_FromLongLong()` and `PyLong_FromSsize_t()`
are now handled by a common macro `PYLONG_FROM_INT` which contains fast paths depending on the
size of the integer to convert. Consequently, `PyLong_FromSsize_t()` for medium-sized integers is faster
by roughly 25%.

---------

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
plashchynski pushed a commit to plashchynski/cpython that referenced this issue Mar 17, 2025
…romSsize_t()` (python#129301)

The implementation of `PyLong_FromLong()`, `PyLong_FromLongLong()` and `PyLong_FromSsize_t()`
are now handled by a common macro `PYLONG_FROM_INT` which contains fast paths depending on the
size of the integer to convert. Consequently, `PyLong_FromSsize_t()` for medium-sized integers is faster
by roughly 25%.

---------

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
picnixz pushed a commit that referenced this issue Mar 30, 2025
…functions (#131211)

Add a fast path for medium-sized integers in `PyLong_FromInt{32,64}` and `PyLong_FromUInt{32,64}`.
@picnixz picnixz closed this as completed Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants