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

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant