KEMBAR78
[mypyc] Use per-type free "lists" for nested functions by JukkaL · Pull Request #19390 · python/mypy · GitHub
Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 7, 2025

Often at most one instance is allocated at any given time, so this improves performance quite significantly in common cases. Uses the freelist feature introduced in #19316.

This speeds up self check by about 0.5% (measured 100 samples). Speeds up this microbenchmark that gets close to the maximal benefit by about 90%:

def f(x: int) -> int:
    def inc(y: int) -> int:
        return y + 1
    return inc(x)

def bench(n: int) -> None:
    for x in range(n):
        f(x)

from time import time
bench(1000)
t0 = time()
bench(50 * 1000 * 1000)
print(time() - t0)

Often at most one instance is allocated at any given time, so this
improves performance quite significantly in common cases.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 7, 2025

@jhance Approved offline but couldn't stamp on the phone.

@JukkaL JukkaL changed the title [mypyc] Use per-type freelists for nested functions [mypyc] Use per-type free "lists" for nested functions Jul 7, 2025
@JukkaL JukkaL merged commit 6600073 into master Jul 7, 2025
13 checks passed
@JukkaL JukkaL deleted the nested-func-freelist branch July 7, 2025 16:12
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.

1 participant