Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Specialize long tail of binary operations using a table. #100239

Open
Assignees
brandtbucher
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
@markshannon

Description

@markshannon

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.

structtable_entry {PyTypeObject*left;PyTypeObject*left;binaryfunc*func;};TARGET(BINARY_OP_TABLE) {PyObject*lhs=SECOND();PyObject*rhs=TOP();Cache*cache=GET_CACHE();structtable_entry*entry=&THE_TABLE[cache->table_index];DEOPT_IF(Py_TYPE(lhs)!=entry->left);DEOPT_IF(Py_TYPE(rhs)!=entry->right);PyObject*res=entry->func(lhs,rhs);if (res==NULL) {        gotoerror;    }STACK_SHRINK(1);Py_DECREF(lhs);Py_DECREF(rhs);SET_TOP(res);DISPATCH();}

An ancillary mapping of(left, right) -> index will be needed for efficient specialization.

It is probably worth keeping the most common operationsint + int,float + float, etc. inline.

We can replaceBINARY_SUBSCR withBINARY_OP ([]) to allow effective specialization ofBINARY_SUBSCR
E.g. subscriptingarray.array[int] can be handled with the registration mechanism described below.

Registering binary functions at runtime

faster-cpython/ideas#162

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp