Skip to content

Conversation

@davidhewitt
Copy link
Member

@davidhewitt davidhewitt commented Dec 12, 2025

In progress work to close #5392

I realised that using Borrowed allows 'a to outlive 'py in argument extraction. This is not always strictly necessary, but in the case of the async code I'm looking into in #5681 it turns out that it's valid for function arguments to have the 'a lifetime but not the 'py lifetime.

This might also be a performance help by removing the need to have references to pointers on stack frames for the BoundRef stuff. EDIT: looks like it doesn't really affect performance, but I still think it's useful for async code.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Jan 8, 2026
@davidhewitt davidhewitt marked this pull request as ready for review January 8, 2026 14:28
Copy link
Contributor

@Tpt Tpt left a comment

Choose a reason for hiding this comment

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

I am not an expert on this code but it seems sensible to me

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

LGTM as well.

It looks like there are not many usages of BoundRef left. Any change that we can adjust them as well and remove it completely?

Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>
@davidhewitt
Copy link
Member Author

It looks like there are not many usages of BoundRef left. Any change that we can adjust them as well and remove it completely?

Potentially as a follow up, yes. It's not completely trivial as there are cases like #[pyfunction(pass_module)] which I think allows &Bound<'py, PyModule> as the argument so a TryFrom<Borrowed<'_, 'py, PyModule>> won't quite work.

@davidhewitt davidhewitt enabled auto-merge January 8, 2026 17:53
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 8, 2026

Merging this PR will improve performance by 10.21%

Summary

⚡ 1 improved benchmark
✅ 97 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
ordered_dunder_methods 2.6 µs 2.4 µs +10.21%

Comparing davidhewitt:extract-argument-borrowed (c351cff) with main (c369c0d)

Open in CodSpeed

@davidhewitt davidhewitt added this pull request to the merge queue Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Borrowed inside of extract_argument.rs

3 participants