Skip to content

CLN/WIP: use conditional nogil #30388

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

Closed
wants to merge 1 commit into from

Conversation

jbrockmendel
Copy link
Member

This is largely an experiment to see how much code we could de-duplicate once cython 0.30.0 comes out and conditional with nogil becomes available. Its a decent amount, less than I'd expected.

Hopefully this can help cython kick the tires.

pass
# FIXME: this breaks with the conditional nogil
#raise ValueError('first not supported for '
# 'non-numeric data')
Copy link
Member Author

Choose a reason for hiding this comment

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

@scoder the "kicking the tires" i mentioned in the OP largely is about this spot. When the commented-out code is enabled here, I get a compile-time error:

                    if rank_t is object:
                        raise ValueError('first not supported for '
                       ^
------------------------------------------------------------

pandas/_libs/algos.pyx:895:24: Trying to acquire the GIL while it is already held.

Is the issue that the compiler doesn't know its in a not-nogil case if it gets here?

Copy link

Choose a reason for hiding this comment

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

I think the GIL acquisition around the raise might happen too early here, before the fused type specialisation, so that it always tries to acquire the GIL even if the with nogil was removed for the specific type.

I think Cython should mark the automatically injected GilStatNode as something internal in InjectGilHandling (module ParseTreeTransforms.py), and then discard the redundant ones in GilCheck instead of throwing this error for them. That would avoid the need for any special casing of fused functions later on. PR welcome.

@jbrockmendel
Copy link
Member Author

@WillAyd anywhere else I missed where we can rip out code using conditional nogil (zero hurry). I'd be interested in your thoughts on the apparently-untested TIEBREAK_FIRST/object code path.

@pilkibun IIRC #27373 was a proof of concept for things we could clean up once cython 0.30.0 is out. Any other suggestions?

@gfyoung gfyoung added Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code labels Dec 22, 2019
@jbrockmendel
Copy link
Member Author

Still interested in thoughts from @WillAyd and @pilkibun (see previous comment), but this PR was just a proof of concept, so closing.

@jbrockmendel jbrockmendel deleted the cy30 branch December 23, 2019 21:51
@WillAyd
Copy link
Member

WillAyd commented Dec 23, 2019

Yep sorry; great idea but admittedly didn't put a ton into review - waiting for Cython to actually release first

@jbrockmendel
Copy link
Member Author

@WillAyd the part that I thought you'd be interested in is that we don't have any tests that go through the TIEBREAK_FIRST/object path. I'm hoping we can either a) un-disallow that and not raise mid-loop or b) raise up-front pre-loop. Pinging you on it is based on a vague recollection that you had worked on it before.

@WillAyd
Copy link
Member

WillAyd commented Dec 23, 2019

Hmm maybe I just forgot but don't recall touching the algos code (did something similar in groupby) so maybe don't fully grasp the context but from glancing at it your suggestion to raise outside of the loop seems logical

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants