Skip to content

gh-126868: Add freelist for compact ints to _PyLong_New #128181

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

Merged
merged 5 commits into from
Dec 26, 2024

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Dec 22, 2024

We add freelist support to _PyLong_New (this was missed/left out in #126868). On the pyperformance suite this increases the percentage of allocations from freelist by roughly 1%. For comparison, the addition of the freelist to _PyLong_FromMedium increased the percentage by roughly 20%. Also note that _PyLong_New is used in the new PyLongWriter_Create (see https://peps.python.org/pep-0757/), so usage with external packages might be a bit higher.

Microbenchmark:

import pyperf

def bench_lshift(loops):
    range_it = range(loops)
    t0 = pyperf.perf_counter()
    for ii in range_it:
        _ = ii << 2
    return pyperf.perf_counter() - t0

if __name__ == "__main__":
    runner = pyperf.Runner()
    runner.bench_time_func("bench_lshift", bench_lshift)

results in:

Mean +- std dev: [main] 44.7 ns +- 3.0 ns -> [pr] 40.9 ns +- 2.3 ns: 1.09x faster

@eendebakpt eendebakpt changed the title gh-26868: Add freelist for compact ints to _PyLong_New gh-126868: Add freelist for compact ints to _PyLong_New Dec 22, 2024
@kumaraditya303 kumaraditya303 enabled auto-merge (squash) December 26, 2024 14:48
@kumaraditya303 kumaraditya303 merged commit 3bd7730 into python:main Dec 26, 2024
44 of 45 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
…on#128181)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants