Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make C modules Python 3 compatible #76

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

trimbo
Copy link
Contributor

@trimbo trimbo commented Aug 26, 2019

_baked.c was the most complicated one. Py3 Unicode implementation
requires initialization. I left the Python 2 implementation alone
because I'm not entirely sure of the overhead being saved with memcpy
right now.

_baked.c was the most complicated one. Py3 Unicode implementation
requires initialization. I left the Python 2 implementation alone
because I'm not entirely sure of the overhead being saved with memcpy
right now.
@trimbo trimbo requested a review from nicksay August 26, 2019 18:59
@trimbo
Copy link
Contributor Author

trimbo commented Aug 26, 2019

No detected performance regression with this.

New:

Spitfire template 9.65 ms
Spitfire template -O1 8.18 ms
Spitfire template -O2 5.70 ms
Spitfire template -O3 5.74 ms
Spitfire template baked 11.02 ms
Spitfire template baked -O1 6.79 ms
Spitfire template baked -O2 6.86 ms
Spitfire template baked -O3 6.90 ms
Spitfire template unfiltered 5.71 ms
Spitfire template unfiltered -O1 2.19 ms
Spitfire template unfiltered -O2 2.16 ms
Spitfire template unfiltered -O3 2.11 ms

Old:

Spitfire template 9.84 ms
Spitfire template -O1 8.37 ms
Spitfire template -O2 5.97 ms
Spitfire template -O3 5.83 ms
Spitfire template baked 10.97 ms
Spitfire template baked -O1 6.95 ms
Spitfire template baked -O2 6.85 ms
Spitfire template baked -O3 6.94 ms
Spitfire template unfiltered 5.74 ms
Spitfire template unfiltered -O1 2.16 ms
Spitfire template unfiltered -O2 2.18 ms
Spitfire template unfiltered -O3 2.13 ms

spitfire/runtime/_baked.c Outdated Show resolved Hide resolved
Py_INCREF(value);
return value;
}
PyObject *args = Py_BuildValue("(N)", value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment on why you are choosing N (and therefore not incrementing the reference count) instead of O?

sp_mod, /* nb_remainder */
};

// SanitizedPlaceholder Type.
static PyTypeObject SanitizedPlaceholderType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PyVarObject_HEAD_INIT(NULL,0 )
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
PyVarObject_HEAD_INIT(NULL,0 )
PyVarObject_HEAD_INIT(NULL, 0)

@@ -151,7 +186,7 @@ static PyTypeObject SanitizedPlaceholderType = {
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
&PyUnicode_Type, /* tp_base */
Copy link
Contributor

@nicksay nicksay Aug 28, 2019

Choose a reason for hiding this comment

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

Since we're conditionally setting tp_base below, let's not set it here too

Suggested change
&PyUnicode_Type, /* tp_base */
0, /* tp_base */

@@ -72,7 +72,7 @@ udn_resolve_udn(PyObject *self, PyObject *args, PyObject *kargs)
return NULL;
}

if (!(PyUnicode_Check(name) || PyString_Check(name))) {
if (!(PyUnicode_Check(name) || PyBytes_Check(name))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to either include bytesobject.h for python2.6+ compatibility of PyBytes_Check or add a PY_MAJOR_VERSION check here like you do elsewhere

@@ -110,7 +110,7 @@ udn_resolve_from_search_list(PyObject *self, PyObject *args, PyObject *keywds)
return NULL;
}

if (!(PyUnicode_Check(name) || PyString_Check(name))) {
if (!(PyUnicode_Check(name) || PyBytes_Check(name))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to either include bytesobject.h for python2.6+ compatibility of PyBytes_Check or add a PY_MAJOR_VERSION check here like you do elsewhere

Copy link
Contributor

@nicksay nicksay left a comment

Choose a reason for hiding this comment

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

Just a couple of changes, I think

Co-Authored-By: Alex Nicksay <nicksay@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants