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

remove more unnecessary C-API usages #30

Merged
merged 1 commit into from
May 26, 2014
Merged

remove more unnecessary C-API usages #30

merged 1 commit into from
May 26, 2014

Conversation

scoder
Copy link

@scoder scoder commented May 5, 2014

  • list comprehensions are actually faster than repeated calls to PyList_Append()
  • Py_XDECREF() works nicely on PyObject* (and the C compiler will usually drop the NULL check)
  • isinstance(x, builtin) translates directly to a PyBuiltin_Check() call

- list comprehensions are actually faster than repeated calls to PyList_Append()
- Py_XDECREF() works nicely on PyObject* (and the C compiler will usually drop the NULL check)
- isinstance(x, builtin) translates directly to a PyBuiltin_Check() call
@eriknw
Copy link
Member

eriknw commented May 5, 2014

Thanks again!

I want to look more closely at a few of these changes so that I may learn from them :)

@mrocklin
Copy link
Member

Whats the status on this? Can it be merged?

@eriknw
Copy link
Member

eriknw commented May 18, 2014

Yeah, I'm sorry for keeping this PR lingering for so long. I really do appreciate your help, @scoder.

I think the majority of the changes in the PR are great and should be merged without question. Some of the changes, however, undo some of the performance tweaks I had made that were demonstrably faster. For example, I found that list comprehensions were slower when using data that I consider representative of typical usage.

Still, it is unreasonable for you, me, or anybody to manually test all these changes to check for performance regressions. benchtoolz (see #22) is usable, and I plan to upload it to github today. This will let us use a common suite of benchmarks that we can easily test against multiple versions of the same function. It also allows for rapid turnaround when a Cython file gets modified, because there is one file per function, and it gets compiled automatically.

Regarding this PR, I think we can merge it, and the onus will be on me to show that a particular tweak is worth it by adding it to benchmarkz (thus allowing others to test and modify the variations too).

I don't think cytoolz is a normal Cython project. For starters, it's generally not recommended to completely reproduce a package in Cython (although I think projects like toolz can be notable exceptions to this rule). If we can reproducibly get a 3% performance gain by using a slightly uglier statement, in general I would choose the 3% gain. toolz is where we keep the pretty code :)

Regarding isinstance(x, builtin) versus PyBuiltin_Check(), I know they produce the exact same C code, but I was undecided which to use. Using PyBuiltin_Check() is explicit in that it can't be optimized further. Most of my other uses of the C API were because I observed a performance increase. Again, the onus will be on me to show that a particular call to the C API is actually faster.

Unless there are comments to the contrary, I plan to merge this tomorrow. Thanks again, scoder, and sorry for the long delay. My hope is that benchtoolz will be worth the delay!

eriknw added a commit that referenced this pull request May 26, 2014
remove more unnecessary C-API usages
@eriknw eriknw merged commit af19b18 into pytoolz:master May 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants