Skip to content
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use AC vectorcall support for the :class:`decimal.Decimal`. This offers
~1.15x speedup on creation of small instances.
6 changes: 4 additions & 2 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3229,7 +3229,7 @@ dec_apply(PyObject *v, PyObject *context)
/* 'v' can have any type accepted by the Decimal constructor. Attempt
an exact conversion. If the result does not meet the restrictions
for an mpd_t, fail with InvalidOperation. */
static PyObject *
static inline PyObject *

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it useful to mark the function as "inline"? Does it impact performance?

PyDecType_FromObjectExact(PyTypeObject *type, PyObject *v, PyObject *context)
{
decimal_state *state = get_module_state_from_ctx(context);
Expand Down Expand Up @@ -3313,6 +3313,7 @@ PyDec_FromObject(PyObject *v, PyObject *context)
}

/*[clinic input]
@vectorcall
@classmethod
_decimal.Decimal.__new__ as dec_new

Expand All @@ -3329,7 +3330,7 @@ trap is active.

static PyObject *
dec_new_impl(PyTypeObject *type, PyObject *value, PyObject *context)
/*[clinic end generated code: output=35f48a40c65625ba input=5f8a0892d3fcef80]*/
/*[clinic end generated code: output=35f48a40c65625ba input=0e5ca99183562cd9]*/
{
decimal_state *state = get_module_state_by_def(type);
CONTEXT_CHECK_VA(state, context);
Expand Down Expand Up @@ -6190,6 +6191,7 @@ static PyType_Slot dec_slots[] = {
{Py_tp_methods, dec_methods},
{Py_tp_getset, dec_getsets},
{Py_tp_new, dec_new},
{Py_tp_vectorcall, dec_vectorcall},

// Number protocol
{Py_nb_add, nm_mpd_qadd},
Expand Down
51 changes: 46 additions & 5 deletions Modules/_decimal/clinic/_decimal.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading