Skip to content

Commit

Permalink
Optimization: Fixup performance regressions incurred
Browse files Browse the repository at this point in the history
* Calling the specialized helper for same types is not
  fast enough, so inline that operation manually there.

* When there is specialization for same types in a function,
  the fallback path cost a lot of performance, so force it to
  a separate function if it's present, and inline otherwise.

* Some of these lessons are still to be applied to binary
  operation code.
  • Loading branch information
kayhayen committed Mar 14, 2021
1 parent 5b7ff1a commit e9ab999
Show file tree
Hide file tree
Showing 16 changed files with 7,766 additions and 2,674 deletions.
1,660 changes: 1,203 additions & 457 deletions nuitka/build/static_src/HelpersOperationInplaceAdd.c

Large diffs are not rendered by default.

496 changes: 361 additions & 135 deletions nuitka/build/static_src/HelpersOperationInplaceBitand.c

Large diffs are not rendered by default.

496 changes: 361 additions & 135 deletions nuitka/build/static_src/HelpersOperationInplaceBitor.c

Large diffs are not rendered by default.

496 changes: 361 additions & 135 deletions nuitka/build/static_src/HelpersOperationInplaceBitxor.c

Large diffs are not rendered by default.

736 changes: 572 additions & 164 deletions nuitka/build/static_src/HelpersOperationInplaceFloordiv.c

Large diffs are not rendered by default.

450 changes: 357 additions & 93 deletions nuitka/build/static_src/HelpersOperationInplaceLshift.c

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions nuitka/build/static_src/HelpersOperationInplaceMatmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ static inline bool _BINARY_OPERATION_MATMULT_LONG_LONG_INPLACE(PyObject **operan
// execute stuff in-place.
}

PyTypeObject *type1 = &PyLong_Type;
PyTypeObject *type2 = &PyLong_Type;

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -55,9 +58,6 @@ static inline bool _BINARY_OPERATION_MATMULT_LONG_LONG_INPLACE(PyObject **operan
#pragma warning(pop)
#endif

PyTypeObject *type1 = &PyLong_Type;
PyTypeObject *type2 = &PyLong_Type;

// No inplace number slot nb_inplace_matrix_multiply available for this type.
assert(type2->tp_as_number == NULL || type2->tp_as_number->nb_inplace_matrix_multiply == NULL);

Expand Down Expand Up @@ -101,6 +101,9 @@ static inline bool _BINARY_OPERATION_MATMULT_OBJECT_LONG_INPLACE(PyObject **oper
// execute stuff in-place.
}

PyTypeObject *type1 = Py_TYPE(*operand1);
PyTypeObject *type2 = &PyLong_Type;

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -111,9 +114,6 @@ static inline bool _BINARY_OPERATION_MATMULT_OBJECT_LONG_INPLACE(PyObject **oper
#pragma warning(pop)
#endif

PyTypeObject *type1 = Py_TYPE(*operand1);
PyTypeObject *type2 = &PyLong_Type;

binaryfunc islot = (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1))
? type1->tp_as_number->nb_inplace_matrix_multiply
: NULL;
Expand Down Expand Up @@ -197,6 +197,9 @@ static inline bool _BINARY_OPERATION_MATMULT_LONG_OBJECT_INPLACE(PyObject **oper
// execute stuff in-place.
}

PyTypeObject *type1 = &PyLong_Type;
PyTypeObject *type2 = Py_TYPE(operand2);

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -207,9 +210,6 @@ static inline bool _BINARY_OPERATION_MATMULT_LONG_OBJECT_INPLACE(PyObject **oper
#pragma warning(pop)
#endif

PyTypeObject *type1 = &PyLong_Type;
PyTypeObject *type2 = Py_TYPE(operand2);

// No inplace number slot nb_inplace_matrix_multiply available for this type.
assert(type2->tp_as_number == NULL || type2->tp_as_number->nb_inplace_matrix_multiply == NULL);

Expand Down Expand Up @@ -290,6 +290,9 @@ static inline bool _BINARY_OPERATION_MATMULT_FLOAT_FLOAT_INPLACE(PyObject **oper
// execute stuff in-place.
}

PyTypeObject *type1 = &PyFloat_Type;
PyTypeObject *type2 = &PyFloat_Type;

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -300,9 +303,6 @@ static inline bool _BINARY_OPERATION_MATMULT_FLOAT_FLOAT_INPLACE(PyObject **oper
#pragma warning(pop)
#endif

PyTypeObject *type1 = &PyFloat_Type;
PyTypeObject *type2 = &PyFloat_Type;

// No inplace number slot nb_inplace_matrix_multiply available for this type.
assert(type2->tp_as_number == NULL || type2->tp_as_number->nb_inplace_matrix_multiply == NULL);

Expand Down Expand Up @@ -342,6 +342,9 @@ static inline bool _BINARY_OPERATION_MATMULT_OBJECT_FLOAT_INPLACE(PyObject **ope
// execute stuff in-place.
}

PyTypeObject *type1 = Py_TYPE(*operand1);
PyTypeObject *type2 = &PyFloat_Type;

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -352,9 +355,6 @@ static inline bool _BINARY_OPERATION_MATMULT_OBJECT_FLOAT_INPLACE(PyObject **ope
#pragma warning(pop)
#endif

PyTypeObject *type1 = Py_TYPE(*operand1);
PyTypeObject *type2 = &PyFloat_Type;

binaryfunc islot = (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1))
? type1->tp_as_number->nb_inplace_matrix_multiply
: NULL;
Expand Down Expand Up @@ -434,6 +434,9 @@ static inline bool _BINARY_OPERATION_MATMULT_FLOAT_OBJECT_INPLACE(PyObject **ope
// execute stuff in-place.
}

PyTypeObject *type1 = &PyFloat_Type;
PyTypeObject *type2 = Py_TYPE(operand2);

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -444,9 +447,6 @@ static inline bool _BINARY_OPERATION_MATMULT_FLOAT_OBJECT_INPLACE(PyObject **ope
#pragma warning(pop)
#endif

PyTypeObject *type1 = &PyFloat_Type;
PyTypeObject *type2 = Py_TYPE(operand2);

// No inplace number slot nb_inplace_matrix_multiply available for this type.
assert(type2->tp_as_number == NULL || type2->tp_as_number->nb_inplace_matrix_multiply == NULL);

Expand Down Expand Up @@ -578,6 +578,9 @@ static inline bool _BINARY_OPERATION_MATMULT_OBJECT_OBJECT_INPLACE(PyObject **op
if (Py_TYPE(*operand1) == Py_TYPE(operand2)) {
}

PyTypeObject *type1 = Py_TYPE(*operand1);
PyTypeObject *type2 = Py_TYPE(operand2);

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
Expand All @@ -588,9 +591,6 @@ static inline bool _BINARY_OPERATION_MATMULT_OBJECT_OBJECT_INPLACE(PyObject **op
#pragma warning(pop)
#endif

PyTypeObject *type1 = Py_TYPE(*operand1);
PyTypeObject *type2 = Py_TYPE(operand2);

binaryfunc islot = (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1))
? type1->tp_as_number->nb_inplace_matrix_multiply
: NULL;
Expand Down
Loading

0 comments on commit e9ab999

Please sign in to comment.