Skip to content

gh-160473: Improve performance of exception raise - #160476

Merged
kumaraditya303 merged 2 commits into
python:mainfrom
eendebakpt:errors-setobject-direct
Oct 31, 2026
Merged

kumaraditya303 merged 2 commits into
python:mainfrom
eendebakpt:errors-setobject-direct

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

See corresponding issue for details.

By the end of _PyErr_SetObject() the value is a normalized exception
instance, so handing it to _PyErr_Restore() only created a reference to
its type that was dropped again, and fetched the traceback of the value
to set it back on the same object.  Call _PyErr_SetRaisedException()
directly instead.  On the free-threaded build this also removes two
atomic operations on the shared refcount of a heap exception type for
every raise from a thread that does not own the type object.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@eendebakpt eendebakpt changed the title gh-16047: Improve performance of exception raise gh-160473: Improve performance of exception raise Oct 23, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 23, 2026
@eendebakpt eendebakpt added skip news and removed type-feature A feature request or enhancement labels Oct 23, 2026
@bedevere-app bedevere-app Bot added type-feature A feature request or enhancement awaiting merge and removed awaiting core review labels Oct 31, 2026
@kumaraditya303
kumaraditya303 enabled auto-merge (squash) October 31, 2026 11:57
@kumaraditya303
kumaraditya303 merged commit 5ffbce7 into python:main Oct 31, 2026
59 checks passed
@eendebakpt
eendebakpt deleted the errors-setobject-direct branch October 31, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants