-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Allow extensions to set a callback to be invoked when a type is modified #91051
Comments
CPython extensions providing optimized execution of Python bytecode (e.g. the Cinder JIT), or even CPython itself (e.g. the faster-cpython project) may wish to cache access to lookups in the class hierarchy (e.g. when resolving the target of a method call). Extensions that perform these optimizations need to know when to invalidate the cached values. CPython already has a mechanism to invalidate its internal state (e.g. the global method cache) when a type is modified: _PyType_Modified. We propose adding an API to allow extensions to set a callback that will be invoked by _PyType_Modified whenever a type, or any ancestor of the type in the class hierarchy, changes. Proposed API:
|
I don't see any discussion here. Are you still interested in getting this in 3.12? What should happen next? Is it a simple PR, or should we have a design discussion first? |
yes, that's the plan!
I think this is a simple PR (similar to #91054), so the next step is to write that PR if the proposed API looks reasonable |
I guess this would go into Include/object.h, where It would be interesting to see how frequently this callback would be called -- I'm a little more worried about the cost than for #91054. Before we go for this, where would the |
I'll work on a PR and we can see what pyperformance says.
Cinder currently just updates I think it's not hard to do this while keeping I'll work on a PR so we have something concrete to discuss. |
Okay, I'm still a little skeptical -- there are a lot of places where But I'd be happy to wait until there's a PR to look at, it's quite possible that I'm missing something. |
@gvanrossum On further thought, I think you were right to be skeptical :) The problem with what I suggested above is that third-party extension code may modify a type and then (if it's well-behaved) call |
Earlier I wrote:
I'm still a tad worried about this. I would guess that the pyperformance benchmarks don't trigger this much, but it does seem it's called whenever any class attribute is modified, including on any successful |
Yes, this is true. I think if pyperformance is fine, that's a reasonable signal that modifying type attributes is very rarely done at all in a hot path (which is what I would think anyway.) Also, the overhead here if no callback is set is not that much. |
The only case I could think of would be if someone keeps statistics in a class variable. I’ve done that. But I’m not too worried it’ll be noticeable. |
Fixed in #91051. |
…-107853) (cherry picked from commit 66e4edd) Co-authored-by: Carl Meyer <[email protected]>
Reopened because not all PRs were merged yet. |
pythonGH-107989) (cherry picked from commit fce93c8) Co-authored-by: Carl Meyer <[email protected]>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: