Skip to content

Inline tuple ops. - #21828

Open
dnwpark wants to merge 2 commits into
python:masterfrom
dnwpark:inline-tuple-ops
Open

Inline tuple ops.#21828
dnwpark wants to merge 2 commits into
python:masterfrom
dnwpark:inline-tuple-ops

Conversation

@dnwpark

@dnwpark dnwpark commented Aug 10, 2026

Copy link
Copy Markdown

Mypyc tuple ops were not yet inlined. I've left CPySequenceTuple_GetSlice un-inlined since it's still kind of heavy.

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR! Left a comment about splitting CPySequenceTuple_GetItem into separate fast and slow paths. Also, can you measure the impact on a small micro-benchmark, and post the results? Sometimes C compilers do something unexpected and an optimization doesn't produce the results you'd expect.

Also, can you add a [mypyc] prefix to the PR title -- this can make it easier to route/prioritize reviews, and to construct release notes, where mypyc changes go into a separate section.

Comment thread mypyc/lib-rt/CPy.h
return (0 <= n && n < size) || (-size <= n && n < 0);
}

static inline PyObject *CPySequenceTuple_GetItem(PyObject *tuple, CPyTagged index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks kind of a large function to inline -- it can slow down compilation and/or increase size of generated code, which can cause L1 cache misses. Also I've seen that compilers sometimes don't want to inline a function if it's big enough, even if declared as inline.

We could instead only inline the fast path -- non-negative, short integer index, no error. The remaining cases would be handled by another, non-inlined function. You can find an example of this in CPyList_GetItem and CPyList_GetItem_.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants