Skip to content

gh-156250: Speed up inherited mapping assignment slot calls - #156258

Open
koxudaxi wants to merge 2 commits into
python:mainfrom
koxudaxi:perf/gh-156250-mapping-assignment-slot
Open

gh-156250: Speed up inherited mapping assignment slot calls#156258
koxudaxi wants to merge 2 commits into
python:mainfrom
koxudaxi:perf/gh-156250-mapping-assignment-slot

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

__setitem__ and __delitem__ share the mp_ass_subscript slot. If a Python subclass of a C type overrides only one of them, the inherited operation is still dispatched through slot_mp_ass_subscript() and called through a wrapper_descriptor.

When lookup returns the expected unbound wrapper descriptor, slot_mp_ass_subscript() now calls the wrapped C slot directly. Python overrides and other descriptors continue through the generic call path.

Benchmark

Release builds on macOS 15.7.1 arm64, based on main at b062727097e997bcb900e11503d3248daac903da. Results are medians from nine alternating-order samples after two warmups.

Median Range
main 1433.26 ms 1420.77–1500.78 ms
this PR 883.81 ms 865.64–934.20 ms

This reduces the collections.Counter assignment benchmark by 549.45 ms (38.34%).

Tests

Tests cover asymmetric dict subclasses, inherited slice deletion on a list subclass, and fallback for custom or incompatible descriptors. The targeted tests pass on regular and free-threaded debug builds.

Fixes #156250

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.

Improve performance of inherited mapping assignment slot calls

1 participant