Skip to content

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