Skip to content

Rough Draft Idea For Migrating Propcache to CPython #125

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Vizonex
Copy link
Contributor

@Vizonex Vizonex commented Jun 25, 2025

What do these changes do?

I moved Propcache to C out of pure boredom/inspiration from having worked a bit on the multidict project for a time so I felt a little bit confident that I could at least pull this off as an outlined plan for optimizing propcache's properties a bit further.

This however is a rough-draft/blue-print idea and like all should be treated as one. I do not expect to do anything with it for the time being and you should treat it as experimental until I am ready to actually begin merging it to it and start replacing the cython script in favor of it.
We will need to add clang-format to pre-commit before we wish to proceed with this large change and I don't expect for this to be implemented until after 0.3.3 has been rolled out.

Edit: Please know that I am a little bit unskilled with writing CPython all by myself so this rough draft might have a few hiccups in the C Code.

Are there changes in behavior for the user?

Should be a little bit more performance now that NULL could be utilized a bit elsewhere. I doubt anyone is going to want a C-API Capsule like I and avetlov are doing to multidict so there may not be a need for one (unless cython starts supporting stuff like it which would be an extremely rare case scenario, incase I made it so that true means success and false indicates failure in a few places in the main header file pc.h).

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@Vizonex Vizonex marked this pull request as draft June 25, 2025 05:18
class Py_Is(Operation):
NAME = "Py_Is"

def replace2(regs):

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have 'self', rather than 'regs', as their first parameter.
# FIXME: add macro after the first header comment
# FIXME: add macro after includes
# FIXME: add macro after: #define PY_SSIZE_T_CLEAN
return line + "\n" + content

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
encoding = "utf-8"
errors = "surrogateescape"

with open(filename, encoding=encoding, errors=errors) as fp:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.
@Dreamsorcerer
Copy link
Member

Personally, I don't think we should be writing anything new in C. We should be using Cython or Rust. But, I'll leave this to bdraco to decide where the project should go.

@bdraco
Copy link
Member

bdraco commented Jun 25, 2025

I think we should only consider C if we can see a 50% or better speed up

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.

3 participants