-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Remove GC Header from constant tuples. #31627
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a cool solution and I'm surprised to see the benchmarks show a speedup. 🙂 My only concern is that Py_SIZE() for non-GC tuples will now return a bad value.
| } | ||
|
|
||
| static int | ||
| tuple_is_gc(PyObject *op) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I considered using tp_is_gc like this but was worried it would have too big an impact on performance. Apparently that wasn't the case. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most tuples like (1,2) or ("foo","bar) are untracked at first GC cycle.
So calling one callback on each tuple is not a big problem.
When adding callback for list, dict, or function objects, we need to measure the performance impact.
| #define PyTuple_GET_SIZE(op) Py_SIZE(_PyTuple_CAST(op)) | ||
| #define _PyTuple_NOGC_FLAG (PY_SSIZE_T_MIN) | ||
| #define _PyTuple_HAS_NO_GC(op) (Py_SIZE(_PyTuple_CAST(op)) & _PyTuple_NOGC_FLAG) | ||
| #define PyTuple_GET_SIZE(op) (Py_SIZE(_PyTuple_CAST(op)) & ~_PyTuple_NOGC_FLAG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Py_SIZE() will still work, right? It will just return a bad value. Won't this break users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will.
Py_SIZE() returns bad value for set, long already.
Maybe, we should officially deprecate using Py_SIZE() to get length of container.
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
faster-cpython/ideas#304