GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-117139: Set up the tagged evaluation stack by Fidget-Spinner · Pull Request #117186 · python/cpython Conversation
|
|
I'm a confused by your description of approach 2:
That does not look like the approach in the PR, which adds new functions that take tagged values. The approach in the PR seems correct. We can change the signatures of internal-only APIs as needed.
If you untag in-place on the stack, you need to I think it's better to do the untagging off the evaluation stack. In the common case, you can have some fixed size |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| typedef union { | ||
| PyObject *obj; | ||
| uintptr_t bits; | ||
| } _Py_TaggedObject; | ||
|
|
||
| #define Py_OBJECT_TAG (0b0) | ||
|
|
||
| #ifdef Py_GIL_DISABLED | ||
| #define Py_CLEAR_TAG(tagged) ((PyObject *)((tagged).bits & ~(Py_OBJECT_TAG))) | ||
| #else | ||
| #define Py_CLEAR_TAG(tagged) ((PyObject *)(uintptr_t)((tagged).bits)) | ||
| #endif | ||
|
|
||
| #define Py_OBJ_PACK(obj) ((_Py_TaggedObject){.bits = (uintptr_t)(obj)}) | ||
|
|
||
| #define Py_TAG_CAST(o) ((_Py_TaggedObject){.obj = (o)}) | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should not make any of these macros or data structures part of the public C API.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I did a mix of both -- for internal functions I converted them to tagged form. For stuff that might be used by other people eg.
Ok I will think about that. That does make sense -- to pass to a scratch buffer for now. If we exceed the buffer I assume we need to untag the C stack then. One thing we might want to be wary of is overflowing the C recursion stack with the current recursion limit. Since this will make |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Also to note: every |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That's undefined behavior in C -- let's avoid it if possible. If we're concerned about external users, add a new function that takes tagged references (and keep the old one unused, if desired).
If we exceed the fixed size buffer we should allocate enough space for a temporary buffer using
I would structure this so that the small, temporary buffer is only used when we perform a vectorcall (and not to a Python function). For example, in pseudo-code: #define N 5 PyObject * PyObject_VectorcallTagged(PyObject *callable, const _Py_TaggedObject *tagged, size_t nargs, PyObject *kwnames) { PyObject *args[N]; if (nargs >= N) { return PyObject_VectorcallTaggedSlow(callable, tagged, nargs, kwnames); } untag(args, tagged, nargs); return PyObject_Vectorcall(callable, args, nargs, kwnames); } PyObject * PyObject_VectorcallTaggedSlow(PyObject *callable, const _Py_TaggedObject *tagged, size_t nargs, PyObject *kwnames) { PyObject *args = PyMem_Malloc(nargs * sizeof(PyObject*)); if (args == NULL) ... untag(args, tagged, nargs); PyObject *res = PyObject_Vectorcall(callable, args, nargs, kwnames); PyMem_Free(args); return res; } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the clear explanation! I will address them tomorrow. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hm, I now recall that the problem of untagging arrays of arguments sunk my attempt (I got it to work, but it was too slow). Hope you fare better! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Could you also configure pre-commit? https://devguide.python.org/getting-started/setup-building/#install-pre-commit index 2bd9c40..3aa7dea 100644 --- a/Tools/cases_generator/analyzer.py +++ b/Tools/cases_generator/analyzer.py @@ -359,7 +359,7 @@ def has_error_without_pop(op: parser.InstDef) -> bool: "Py_XDECREF_STACKREF", "Py_INCREF_STACKREF", "Py_XINCREF_TAGGED", - "Py_NewRef_StackRef", + "Py_NewRef_StackRef", "Py_INCREF", "_PyManagedDictPointer_IsValues", "_PyObject_GetManagedDict", |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot nogil |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @Fidget-Spinner for commit d59145b 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Here are results from Sam's microbenchmark suite testing scalability. Note that I've only implemented deferred refcounting for method and function calls. Notice that All tests pass except ASAN. I am now happy with the state this PR is in. So I will close this and start upstreaming things in peices. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Benchmarks for the default build suggest a 1% speedup https://github.com/faster-cpython/benchmarking-public/blob/main/results/bm-20240426-3.13.0a6%2B-d59145b/bm-20240426-linux-x86_64-Fidget%252dSpinner-tagged_evaluation_st-3.13.0a6%2B-d59145b-vs-base.md |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.