[New-bugs-announce] [issue39156] Break up COMPARE_OP into logically distinct operations.

Mark Shannon report at bugs.python.org
Sun Dec 29 14:44:42 EST 2019


New submission from Mark Shannon <mark at hotpy.org>:

Currently the COMPARE_OP instruction performs one of four different tasks.
We should break it up into four different instructions, that each performs only one of those tasks.

The four tasks are:
  Rich comparison (>, <, ==, !=, >=, <=)
  Identity comparison (is, is not)
  Contains test (in, not in)
  Exception matching

The current implementation involves an unnecessary extra dispatch to determine which task to perform.
Comparisons are common operations, so this extra call and unpredictable branch has a cost.

In addition, testing for exception matching is always followed by a branch, so the test and branch can be combined.

I propose adding three new instructions and changing the meaning of `COMPARE_OP`.

COMPARE_OP should only perform rich comparisons, and should call `PyObject_RichCompare` directly.
IS_OP performs identity tests, performs no calls and cannot fail.
CONTAINS_OP tests for 'in and 'not in' and should call `PySequence_Contains` directly.
JUMP_IF_NOT_EXC_MATCH Tests whether the exception matches and jumps if it does not.

----------
components: Interpreter Core
messages: 359002
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: Break up COMPARE_OP into logically distinct operations.
type: performance
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39156>
_______________________________________


More information about the New-bugs-announce mailing list