Skip to content

gh-109181: Speed up Traceback object creation by lazily compute the line number #111548

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 1 commit into from
Oct 31, 2023

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Oct 31, 2023

@pablogsal
Copy link
Member Author

From this test:

from time import perf_counter as time
from timeit import repeat

for e in range(2, 6):
    n = 10 ** e
    exec(f'''def f():
        if 0 == 1:
            {'unreached;' * n}
        try:
            raise RuntimeError
        except RuntimeError:
            pass''')
    number = 10**6 // n
    t = min(repeat(f, number=number)) / number
    print(f'{n:6} {t * 1e6 :7.1f} μs')

Before:

./python.exe bloch.py
   100     1.4 μs
  1000    10.5 μs
 10000   102.4 μs
100000  1241.8 μs

After:

./python.exe bloch.py
   100     0.7 μs
  1000     0.6 μs
 10000     0.5 μs
100000     0.5 μs

@pablogsal pablogsal added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Oct 31, 2023
@pablogsal pablogsal enabled auto-merge (squash) October 31, 2023 14:45
@pablogsal pablogsal requested a review from ambv October 31, 2023 14:50
@pablogsal pablogsal merged commit abb1542 into python:main Oct 31, 2023
@pablogsal pablogsal deleted the gh-109181 branch October 31, 2023 15:02
@miss-islington-app
Copy link

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @pablogsal, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker abb15420c11d9dda9c89f74eac8417240b321109 3.12

@miss-islington-app
Copy link

Sorry, @pablogsal, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker abb15420c11d9dda9c89f74eac8417240b321109 3.11

@bedevere-app
Copy link

bedevere-app bot commented Oct 31, 2023

GH-111550 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Oct 31, 2023
pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 31, 2023
…compute the line number (pythonGH-111548)

Signed-off-by: Pablo Galindo <[email protected]>.
(cherry picked from commit abb1542)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Oct 31, 2023

GH-111551 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Oct 31, 2023
pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 31, 2023
…compute the line number (pythonGH-111548)

Signed-off-by: Pablo Galindo <[email protected]>.
(cherry picked from commit abb1542)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 31, 2023
…compute the line number (pythonGH-111548)

Signed-off-by: Pablo Galindo <[email protected]>.
(cherry picked from commit abb1542)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Signed-off-by: Pablo Galindo <[email protected]>
pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 31, 2023
…compute the line number (pythonGH-111548)

Signed-off-by: Pablo Galindo <[email protected]>.
(cherry picked from commit abb1542)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Signed-off-by: Pablo Galindo <[email protected]>
pablogsal added a commit that referenced this pull request Oct 31, 2023
pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 31, 2023
pablogsal added a commit that referenced this pull request Oct 31, 2023
FullteaR pushed a commit to FullteaR/cpython that referenced this pull request Nov 3, 2023
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
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