Repository navigation
Specialize long tail of binary operations using a table. #100239
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedperformancePerformance or resource usagePerformance or resource usage
on Dec 14, 2022 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Nov 28, 2023 - added 9 commits that reference this issue
on Jan 10, 2025 #128722 broke repeated runs of
test.test_ctypes.test_random_things.CallbackTracbackTestCase.test_FloatDivisionError, on several refleak buildbots e.g. https://buildbot.python.org/#/builders/920/builds/1287Is it possible to fix this today?
#128722 broke repeated runs of
test.test_ctypes.test_random_things.CallbackTracbackTestCase.test_FloatDivisionError, on several refleak buildbots e.g. https://buildbot.python.org/#/builders/920/builds/1287Is it possible to fix this today?
I'll take care of it!
- added a commit that references this issue
on Jan 19, 2025 17 remaining items
- added a commit that references this issue
on Feb 19, 2026 - added a commit that references this issue
on Apr 6, 2026 Some additional ideas for further improvements #128956 (comment)
- added a commit that references this issue
on Apr 16, 2026
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
There is a desire to specialize the remaining binary operations (including binary subscript).
However adding more and more specialized instructions is likely to make performance worse.
This idea is to have a lookup table of types pairs and function pointers. This is less efficient than inlining the code, but more extensible.
A single instruction can then support up to 256 specializations.
This will only work for immutable classes.
An ancillary mapping of
(left, right) -> indexwill be needed for efficient specialization.It is probably worth keeping the most common operations
int + int,float + float, etc. inline.We can replace
BINARY_SUBSCRwithBINARY_OP ([])to allow effective specialization ofBINARY_SUBSCRE.g. subscripting
array.array[int]can be handled with the registration mechanism described below.Registering binary functions at runtime
faster-cpython/ideas#162
Linked PRs
sq_repeathelpers forBINARY_OP_EXTEND#148791