GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-95245: Store object values and dict pointers in single tagged pointer. by markshannon · Pull Request #95278 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Jul 26, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This is the first part of #95245. Part two will move the weakrefs pointer into the object pre-header.

I have chosen to tag the values pointer, rather than the dict pointer, because it allows _PyObject_GetDictPtr(PyObject *obj) to continue to return a valid pointer.

  • Issue: Reduce the size of plain Python objects from 8 to 6 machine words. #95245

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
markshannon added 4 commits July 25, 2022 15:33
@markshannon
Store object values and dict pointers in single tagged pointer.
ffde281
@markshannon
Merge branch 'main' into merge-dict-and-values-pointers
48563b3
@markshannon
Fixup merge by deduplicating visit/clear functions and moving declara…
9fdad79
…tion to correct header.
@markshannon
Remove some pointless inline functions and better inforce invariants.
da9b388
@markshannon
markshannon requested a review from methane as a code owner July 26, 2022 11:56
@bedevere-bot bedevere-bot added the awaiting core review label Jul 26, 2022
@markshannon
Add news
0d06096
@markshannon

markshannon commented Jul 26, 2022

Copy link
Copy Markdown
Member Author

No change in performance

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Jul 27, 2022
View reviewed changes
Comment thread Objects/dictobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Jul 27, 2022
View reviewed changes
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@markshannon
Implement kumaraditya303 suggestions.
562c103
iritkatriel
iritkatriel reviewed Jul 28, 2022
View reviewed changes
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel
iritkatriel reviewed Jul 28, 2022
View reviewed changes
Comment thread Objects/object.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Jul 28, 2022

Copy link
Copy Markdown
Member

Is there any documentation about this? It's pretty intricate.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Aug 1, 2022

Copy link
Copy Markdown
Member Author

I was going to document this once I'd done the second part of #95245
Something like this: https://github.com/faster-cpython/cpython/blob/document-object-layout/Objects/object_layout.md

corona10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel
iritkatriel approved these changes Aug 1, 2022
View reviewed changes

@iritkatriel iritkatriel left a comment

Copy link
Copy Markdown
Member

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.

I have no more comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Aug 1, 2022
@markshannon
markshannon merged commit de388c0 into python:main Aug 1, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Aug 1, 2022
matthiasgoergens
matthiasgoergens reviewed Aug 26, 2022
View reviewed changes
Comment thread Include/internal/pycore_object.h
static inline void
_PyDictOrValues_SetValues(PyDictOrValues *ptr, PyDictValues *values)
{
ptr->values = ((char *)values) - 1;

@matthiasgoergens matthiasgoergens Aug 26, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

I'm curious why this one is a -1? Naively, I would have expected something like (|1), ie setting the lowest bit. Which would be equivalent to +1.

I assume there's something that goes horribly wrong with that native approach that I am missing, though?

(As far as I can tell, subtracting one should also work. Not sure what C does with null pointers in this context, though.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@erlend-aasland erlend-aasland Aug 26, 2022

Copy link
Copy Markdown
Contributor

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.

_PyDictOrValues_SetValues mutates the pointer; _PyDictOrValues_GetValues restores the pointer. Think of it as $f(x) = y$ and $f^{-1}(y) = x$. Currently, $f(x) = x - 1$ and $f^{-1}(y) = y + 1$. If we'd used +1, as you suggest, we'd have to undo that using -1 iso. +1. AFAICS, either way is fine.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@matthiasgoergens matthiasgoergens Aug 26, 2022

Copy link
Copy Markdown
Contributor

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.

Thanks for explaining!

I am working on a prototype with a tagged pointer elsewhere in the code, I so I was looking for exiting examples to learn from.

Thanks for confirming that either way is fine.

I was just wrecking my brain about whether there's something more going on that I was missing. (And something that I would thus be bound to get horriby wrong in my code, where I want to store either a pointer directly, or an odd integer, in the same memory location.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erlend-aasland erlend-aasland mentioned this pull request Nov 29, 2022
Lazily create dictionaries for plain Python objects #89503
Closed
@markshannon
markshannon deleted the merge-dict-and-values-pointers branch September 26, 2023 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland erlend-aasland left review comments
@kumaraditya303 kumaraditya303 kumaraditya303 left review comments
@iritkatriel iritkatriel iritkatriel approved these changes
@methane methane Awaiting requested review from methane methane is a code owner
+1 more reviewer
@matthiasgoergens matthiasgoergens matthiasgoergens left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@markshannon @iritkatriel @matthiasgoergens @erlend-aasland @kumaraditya303 @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.