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

Optimise pyo3 use #16

Merged
merged 1 commit into from
Nov 3, 2024
Merged

Optimise pyo3 use #16

merged 1 commit into from
Nov 3, 2024

Conversation

masklinn
Copy link
Collaborator

@masklinn masklinn commented Nov 3, 2024

While this has not been profiled, it seems rather unlikely that the python implementation uses the same allocator as Rust (whether system or other). This means returning a String is an extra allocation as that will need to be copied again to a PyString on the ouput. Which is just dumb.

Copy the internal Cow directly to a PyString on output. On input, a String is necessary as there's no way to lifetime properly from Python, so the extractors need to be 'static.

While this has not been profiled, it seems rather unlikely that the
python implementation uses the same allocator as Rust (whether
system or other). This means *returning* a `String` is an extra
allocation as that will need to be copied again to a `PyString` on the
ouput. Which is just dumb.

Copy the internal `Cow` directly to a `PyString` on output. On input,
a `String` is necessary as there's no way to lifetime properly from
Python, so the extractors need to be `'static`.
@masklinn masklinn enabled auto-merge (rebase) November 3, 2024 12:38
@masklinn masklinn merged commit ca40376 into ua-parser:main Nov 3, 2024
13 checks passed
@masklinn masklinn deleted the pyo3-opt branch November 3, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant