From bc2f49454c330a83373e1f00c3de717dad4070ef Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 11 Nov 2016 01:43:56 +0100 Subject: Use PyThreadState_GET() in performance critical code It seems like _PyThreadState_UncheckedGet() is not inlined as expected, even when using gcc -O3. --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 918f4dffab..0c38f7cf0c 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -161,7 +161,7 @@ PyErr_SetString(PyObject *exception, const char *string) PyObject * PyErr_Occurred(void) { - PyThreadState *tstate = _PyThreadState_UncheckedGet(); + PyThreadState *tstate = PyThreadState_GET(); return tstate == NULL ? NULL : tstate->curexc_type; } -- cgit v1.2.1 From 18dea7d67d8b263dd8b49e1d44dcb09ca86ad08a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 11 Nov 2016 02:13:35 +0100 Subject: Issue #28618: Make hot functions using __attribute__((hot)) When Python is not compiled with PGO, the performance of Python on call_simple and call_method microbenchmarks depend highly on the code placement. In the worst case, the performance slowdown can be up to 70%. The GCC __attribute__((hot)) attribute helps to keep hot code close to reduce the risk of such major slowdown. This attribute is ignored when Python is compiled with PGO. The following functions are considered as hot according to statistics collected by perf record/perf report: * _PyEval_EvalFrameDefault() * call_function() * _PyFunction_FastCall() * PyFrame_New() * frame_dealloc() * PyErr_Occurred() --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 0c38f7cf0c..d459fae622 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -158,7 +158,7 @@ PyErr_SetString(PyObject *exception, const char *string) } -PyObject * +PyObject* _Py_HOT_FUNCTION PyErr_Occurred(void) { PyThreadState *tstate = PyThreadState_GET(); -- cgit v1.2.1 From ba86008aac6890c5c4a2c6d30ea8110f228d483e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 20 Nov 2016 12:16:46 +0200 Subject: Issue #19569: Compiler warnings are now emitted if use most of deprecated functions. --- Python/errors.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 1463cdca3f..01304d25a1 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -582,9 +582,7 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename) PyObject * PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL); Py_XDECREF(name); return result; @@ -691,9 +689,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithUnicodeFilename( int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(exc, ierr, name, @@ -729,9 +725,7 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : - NULL; + PyObject *name = filename ? PyUnicode_FromWideChar(filename, -1) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObjects( PyExc_OSError, ierr, name, NULL); -- cgit v1.2.1 From 40273ec4f37c65c13a09d0ac23b08c99ebe2f1a3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 5 Dec 2016 17:04:32 +0100 Subject: Issue #28858: Remove _PyObject_CallArg1() macro Replace _PyObject_CallArg1(func, arg) with PyObject_CallFunctionObjArgs(func, arg, NULL) Using the _PyObject_CallArg1() macro increases the usage of the C stack, which was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this issue. --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 01304d25a1..74283c9be3 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -62,7 +62,7 @@ _PyErr_CreateException(PyObject *exception, PyObject *value) return PyObject_Call(exception, value, NULL); } else { - return _PyObject_CallArg1(exception, value); + return PyObject_CallFunctionObjArgs(exception, value, NULL); } } -- cgit v1.2.1