Skip to content

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

methane
Copy link
Member

@methane methane commented Mar 1, 2022

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a 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)
Copy link
Member

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. 🙂

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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.

methane and others added 2 commits March 2, 2022 07:50
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants