Skip to content
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

add PyBackedStr and PyBackedBytes #3802

Merged
merged 5 commits into from Feb 15, 2024
Merged

Conversation

davidhewitt
Copy link
Member

Split from #3708

cc @adamreichold this is inspired by #3784 (comment)

I didn't really want to think too hard about a generic T for this type, instead I wanted to just introduce two special cases which should be able to replace &str or Cow<u8>. These types might end up being temporary just until we can add the second lifetime to FromPyObject, or maybe we learn from these and refine further later.

This depends on #3801 to compile.

Copy link

codspeed-hq bot commented Feb 5, 2024

CodSpeed Performance Report

Merging #3802 will degrade performances by 20.41%

Comparing davidhewitt:backed-str (6aec91c) with main (f3ddd02)

Summary

⚡ 1 improvements
❌ 2 regressions
✅ 76 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main davidhewitt:backed-str Change
list_via_downcast 157.2 ns 185 ns -15.02%
list_via_extract 364.4 ns 308.9 ns +17.99%
not_a_list_via_downcast 216.7 ns 272.2 ns -20.41%

@martindurant
Copy link

martindurant commented Feb 9, 2024

Thank you, this is exactly the kind of code I have used and I see elsewhere for zero-copy of python bytes. What remains to be done in this PR?

(I care more about bytes than strings, so would be happy to see this without the UTF8 encode)

src/lib.rs Outdated Show resolved Hide resolved
src/py_backed.rs Outdated Show resolved Hide resolved
src/py_backed.rs Outdated Show resolved Hide resolved
src/py_backed.rs Outdated Show resolved Hide resolved
@davidhewitt davidhewitt marked this pull request as ready for review February 14, 2024 23:25
src/pybacked.rs Outdated Show resolved Hide resolved
@adamreichold adamreichold added this pull request to the merge queue Feb 15, 2024
Merged via the queue into PyO3:main with commit dc8b948 Feb 15, 2024
66 of 68 checks passed
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.

None yet

3 participants