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

PEP 756: Give up on copying memory #3999

Merged
merged 3 commits into from
Sep 26, 2024
Merged

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 26, 2024


📚 Documentation preview 📚: https://pep-previews--3999.org.readthedocs.build/

@vstinner
Copy link
Member Author

@zooba @pitrou: I tried hard to fit memory copies and conversions in PEP 756, but apparently there are too many drawbacks and most users expect/require O(1) complexity. Here is a change to give up on any kind of implicit conversion and only export what we have in O(1). It means giving up on exporting UTF-8 on CPython 3.14 which is IMO an acceptable tradeoff. You can use PyUnicode_AsUTF8AndSize() which is already available.

Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

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

Thanks for this change.

I don't know that referring to "most users expect" is necessarily true or helpful, but expectations will certainly be clearer.

peps/pep-0756.rst Outdated Show resolved Hide resolved
Co-authored-by: Steve Dower <[email protected]>
@vstinner
Copy link
Member Author

vstinner commented Sep 26, 2024

I don't know that referring to "most users expect" is necessarily true or helpful, but expectations will certainly be clearer.

Well, in the PEP 756 discussions, it seems like the majority has the expectation that an export has a O(1) complexity and would be unhappy if somehow an export can cost O(n) on a different Python version or implementation.

@pitrou
Copy link
Member

pitrou commented Sep 26, 2024

I think the users we're trying to satisfy here are the ones you listed in the PEP: https://peps.python.org/pep-0756/#usage-of-pep-393-c-apis

@zooba
Copy link
Member

zooba commented Sep 26, 2024

Well, in the PEP 756 discussions ...

I guess I feel like I dominated the discussion too much and you shouldn't treat me as representing multiple users 😆

I think the users we're trying to satisfy here are ...

Indeed, though I'm only aware of a deep dive going into markupsafe, which did have a legitimate use for O(1) access and was willing to implement their search/replace algorithms multiple times in order to benefit from it. I've got no idea how many others are in the same category, and I don't think many of them spoke up.

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

Nice edits. Thank you for the clarity.

@vstinner vstinner merged commit aced24f into python:main Sep 26, 2024
6 checks passed
@vstinner vstinner deleted the pep756_no_copy branch September 26, 2024 18:37
@vstinner
Copy link
Member Author

Merged, thanks for reviews.

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.

4 participants