python / python/cpython

Use tagged pointers for more efficient integer operations.

Open
#132,509 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core performance type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

From the discourse discussion:

Integers are ubiquitous, both in Python code and the virtual machine.
However our representation of integers is somewhat clunky and inefficient.

There is an old technique for handling ints efficiently in dynamic language VMs, called tagged pointers.
A normal object pointer always has its low bits set to zero, as objects are 8 or 16 byte aligned in memory.
We can use those low bits as “tags” to denote the meaning of the high bits.
Historically, the low bit has been set to zero to indicate that the high bits are a pointer, and to 1 to indicate that the high bits are an integer.

We already use another tagging scheme within the interpreter and in the frame stack, the tag indicating whether the reference is borrowed.

I expect to start small with this, initially just fixing https://github.com/python/cpython/issues/132508 then improving the performance of iteration over lists and tuples.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/using-tagged-pointers-to-support-efficient-integer-operations/87950

Linked PRs
  • gh-157353

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading issue #132508, the linked pull request #157353, and the referenced Discourse discussion to understand the proposed tagged-pointer representation and current work. The issue does not name files, tests, or a bounded implementation task; completion would require defining and validating a broader interpreter and VM design.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.