Skip to content

Conversation

@heliang666s
Copy link
Contributor

@heliang666s heliang666s commented Jul 1, 2025

@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@heliang666s heliang666s changed the title gh136157:Optimize asyncio.to_thread to avoid contextvars.copy_context() overhead for empty contexts gh-136157:Optimize asyncio.to_thread to avoid contextvars.copy_context() overhead for empty contexts Jul 1, 2025
@bedevere-app
Copy link

bedevere-app bot commented Jul 1, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz picnixz changed the title gh-136157:Optimize asyncio.to_thread to avoid contextvars.copy_context() overhead for empty contexts gh-136157: Optimize asyncio.to_thread to avoid contextvars.copy_context() overhead for empty contexts Jul 1, 2025
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide some benchmarks.

Comment on lines +24 to +27
if not ctx:
callback = functools.partial(func, *args, **kwargs)
else:
callback = functools.partial(ctx.run, func, *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, couldn't we alternatively add a fast path to Context.run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Please see the issue for details.

@ZeroIntensity
Copy link
Member

Please provide some benchmarks.

Ah, oops, didn't look at the issue. It would be helpful to put them in the PR description as well.

@heliang666s
Copy link
Contributor Author

heliang666s commented Jul 2, 2025

Please provide some benchmarks.

image
the benchmark code please see the issue for details.

@ZeroIntensity
Copy link
Member

Attached issue was closed, so I'm closing this as well.

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.

2 participants