Skip to content

Inline __pyx_memoryview_slice_memviewslice as C function#7558

Merged
da-woods merged 1 commit intocython:masterfrom
da-woods:slice_memviewslice-inline2
Mar 9, 2026
Merged

Inline __pyx_memoryview_slice_memviewslice as C function#7558
da-woods merged 1 commit intocython:masterfrom
da-woods:slice_memviewslice-inline2

Conversation

@da-woods
Copy link
Copy Markdown
Contributor

@da-woods da-woods commented Mar 9, 2026

Partial fix for #7521.

This came up in a particular scikit-image microbenchmark so almost certainly isn't the only thing. But it looks like this particular function relies heavily on unused branches being eliminated so really wants to be inlined.

On the scikit-image microbenchmark, it's now actually faster with the shared utility code than without. I'm not sure why but possibly just the effect of the inline keyword.

The shared utility module itself doesn't change size at all with this fix (despite moving it to C)

Alternative to #7557. I prefer this version because it has less duplication but there's some risk of errors in the translation to C

Partial fix for cython#7521.

This came up in a particular scikit-image microbenchmark so almost certainly isn't the only thing. But it looks like this particular function relies heavily on unused branches being eliminated so really wants to be inlined.

On the scikit-image microbenchmark, it's now actually faster with the shared utility code than without. I'm not sure why but possibly just the effect of the inline keyword.

The shared utility module itself doesn't change size at all with this fix (despite moving it to C)

Alternative to cython#7557
Copy link
Copy Markdown
Contributor

@scoder scoder left a comment

Choose a reason for hiding this comment

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

Right, there's not much of a reason to write this in Cython code that needs to be translated on each run.

@scoder scoder added this to the 3.3 milestone Mar 9, 2026
@da-woods da-woods merged commit b9c639c into cython:master Mar 9, 2026
93 checks passed
@da-woods da-woods deleted the slice_memviewslice-inline2 branch March 9, 2026 18:19
scoder pushed a commit that referenced this pull request Mar 21, 2026
Partial fix for #7521

Backport to 3.2.x of #7558

This came up in a particular scikit-image microbenchmark so almost
certainly isn't the only thing. But it looks like this particular
function relies heavily on unused branches being eliminated so really
wants to be inlined.

On the scikit-image microbenchmark, it's now actually faster with the
shared utility code than without. I'm not sure why but possibly just the
effect of the inline keyword.

The shared utility module itself shrinks by 32bytes with this fix.

Alternative to #7557. I prefer this
version because it has less duplication but there's some risk of errors
in the translation to C.
@scoder scoder modified the milestones: 3.3, 3.2.5 Mar 21, 2026
@scoder
Copy link
Copy Markdown
Contributor

scoder commented Mar 21, 2026

3.2.x commit is db55017

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.

2 participants