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
Lazily compute lineno of tracebacks for efficient exception handling #95238
Comments
PR #95237 computes line number lazily. This microbenchmark shows a 25% speedup when handling exception: import pyperf
from pyperf import Runner
def bench(loops):
x = object()
t1 = pyperf.perf_counter()
for i in range(loops):
try:
x.y
except AttributeError:
pass
t2 = pyperf.perf_counter()
return t2 - t1
runner = Runner()
runner.bench_time_func('bench exception handling', bench) Benchmark results:
This is on Linux release build without PGO and LTO. |
PR #95237 makes @scoder @da-woods Can you confirm if Cython will be affected by this change? Thanks! See also discourse discussion |
I did a quick search of Cython and couldn't find any use of |
Results from a pyperformance run would be more informative than the microbenchmark when it comes to deciding about the deprecation timeline exemption asked for in python/steering-council#136. |
Another benchmark speedup by 50% on Linux gcc with PGO build: import pyperf
from pyperf import Runner
def bench(loops):
x = {1: "foo", 2: "baz"}
t1 = pyperf.perf_counter()
for _ in range(loops):
try:
x["fooz"]
except KeyError:
pass
t2 = pyperf.perf_counter()
return t2 - t1
runner = Runner()
runner.bench_time_func('bench exception handling', bench) Results
|
pyperformance has no benchmarks which use exception handling in hot paths. The speedup if any would be dominated by the noise in the benchmark itself. Also moving pyperformance needle by even 1% isn't easy, the accumulation of these kinds of targeted improvements will result in 1% or more but just one change isn't going to do it. |
Will be implemented as part of #96709 |
By lazily computing
tb_lineno
of tracebacks, we can avoid parsing the line and column table and avoid a lot of overhead that comes with accessing line number information.See faster-cpython/ideas#407 for discussion.
The text was updated successfully, but these errors were encountered: