FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-119477: Analyze through BUILD_TUPLE and BINARY_SUBSCR_TUPLE_INT by tekknolagi · Pull Request #119478 · python/cpython · GitHub

Repository navigation

gh-119477: Analyze through BUILD_TUPLE and BINARY_SUBSCR_TUPLE_INT - #119478

Closed
tekknolagi wants to merge 2 commits into
python:mainfrom
tekknolagi:mb-analyze-through-tuples
Closed

tekknolagi wants to merge 2 commits into
python:mainfrom
tekknolagi:mb-analyze-through-tuples

Conversation

tekknolagi commented May 23, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor

Make an symbolic tuple arena so we can allocate arrays of pointers to
other symbols.

Co-authored-by: @Fidget-Spinner

Make an symbolic tuple arena so we can allocate arrays of pointers to
other symbols.
tekknolagi changed the title Analyze through BUILD_TUPLE and BINARY_SUBSCR_TUPLE_INT gh-119477: Analyze through BUILD_TUPLE and BINARY_SUBSCR_TUPLE_INT May 23, 2024
tekknolagi marked this pull request as ready for review May 23, 2024 21:26

markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This increases the size of the stack allocated arena considerably, maybe causing stack overflows.
I've suggested how to address this in the comments.

FYI, We plan to merge BINARY_SUBSCR into BINARY_OP soon.

int flags; // 0 bits: Top; 2 or more bits: Bottom
PyTypeObject *typ; // Borrowed reference
PyObject *const_val; // Owned reference (!)
int tuple_count;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you move this after the flags, and it doesn't need 32 bits.

PyTypeObject *typ; // Borrowed reference
PyObject *const_val; // Owned reference (!)
int tuple_count;
struct _Py_UopsSymbol **tuple_val;

markshannon May 24, 2024 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you use indexes, rather than pointers? We can fit 6 10-bit indexes into a 64 bit int.
We really don't care about tuples with len() > 6 and we are already using too much stack memory for these data structures.

Would it be possible to use a union, and overlap this field with const_val?

_Py_UopsSymbol arena[TY_ARENA_SIZE];
} ty_arena;

typedef struct tup_arena {

markshannon May 24, 2024 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This shouldn't be necessary, if we use indexes into the arena, instead of pointers.

extern _Py_UopsSymbol *_Py_uop_sym_new_type(
_Py_UOpsContext *ctx, PyTypeObject *typ);
extern _Py_UopsSymbol *_Py_uop_sym_new_tuple(_Py_UOpsContext *ctx, int count);
extern _Py_UopsSymbol *_Py_uop_sym_tuple_at(_Py_UopsSymbol *sym, int idx);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you use get_item, not at, for consistency with the rest of the code base?
Can you add _Py_uop_sym_tuple_set_item as well?

assert(tup != NULL);
assert(!ctx->out_of_space);
for (int i = 0; i < oparg; i++) {
tup->tuple_val[i] = values[i];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Use sym_tuple_set_item(tup, i, values[i]) for better encapsulation.

op(_BINARY_SUBSCR_TUPLE_INT, (tuple, sub -- res)) {
if (sym_has_type(tuple) && sym_matches_type(tuple, &PyTuple_Type) && sym_is_const(sub) ) {
PyObject* value = sym_get_const(sub);
Py_ssize_t index = ((PyLongObject*)value)->long_value.ob_digit[0];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is no guarantee that value is an int.

}
}

op(_BINARY_SUBSCR_TUPLE_INT, (tuple, sub -- res)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This optimization applies to all BINARY_SUBSCR variants, although it is much more likely to apply here.

bedevere-app Bot commented May 24, 2024

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Copy Markdown
Member

@tekknolagi do you plan to continue working on this?

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 16, 2026

Copy link
Copy Markdown
Member

This is done, thanks everyone!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL