Skip to content

Conversation

@pitrou
Copy link
Member

@pitrou pitrou commented Jan 30, 2018

OwnedRef API cleaned up:

  • doesn't try to take the GIL in its destructor anymore
  • reset() decrefs the underlying pointer
  • detach() unowns the pointer without decrefing it

Add OwnedRefNoGIL which forcefully takes the GIL in its destructor, at the expense of runtime performance.

OwnedRef API cleaned up:
- doesn't try to take the GIL in its destructor anymore
- reset() decrefs the underlying pointer
- detach() unowns the pointer without decrefing it

Add OwnedRefNoGIL which forcefully takes the GIL in its destructor,
at the expense of runtime performance.
@pitrou
Copy link
Member Author

pitrou commented Jan 30, 2018

This PR has an interesting performance impact here:

$ python -m timeit -s "import pyarrow as pa; ty=pa.int64(); data=[None]*1000000" "pa.array(data, type=ty)"
  • before: 27.1 msec per loop
  • after: 14.9 msec per loop

Probably because of less calls to PyGILState_Ensure.

@wesm
Copy link
Member

wesm commented Jan 30, 2018

On the subject of performance, our Airspeed / ASV setup is in a state of disrepair. We should start building a suite of microbenchmarks so we can monitor the performance of operations like these in a more systematic way. There are already some JIRAs open about getting this cleaned up and well-documented for other developers, would you be interested in taking a look?

@pitrou
Copy link
Member Author

pitrou commented Jan 30, 2018

There are already some JIRAs open about getting this cleaned up and well-documented for other developers, would you be interested in taking a look?

Definitely, can you give me some pointers?

@wesm
Copy link
Member

wesm commented Jan 30, 2018

See https://issues.apache.org/jira/browse/ARROW-1861

There is already an asv.conf.json in https://github.com/apache/arrow/tree/master/python and a couple of benchmarks, but I tried to run it myself some time ago and ran into issues. It's not documented at all AFAICT. pandas has a pretty deep suite of benchmarks https://github.com/pandas-dev/pandas/tree/master/asv_bench

Copy link
Contributor

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

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

@pitrou LGTM

Is it correct to say that now callers must be more careful about acquiring the GIL before making calls into the Python C API (assuming use of OwnedRef)?

@wesm
Copy link
Member

wesm commented Jan 30, 2018

I need to take a closer look at our various usages of OwnedRef -- there are places where we have OwnedRef as member variables of classes, so the risk is that an OwnedRef might be destructed at the same time that a PyAcquireGIL lock is being destructed, so we could be relying on the order of destruction to make sure the GIL is held. We'll need to prevent this by making sure that no OwnedRef can be destructed at the same time as a GIL is released by RAII

@pitrou
Copy link
Member Author

pitrou commented Jan 31, 2018

I need to take a closer look at our various usages of OwnedRef -- there are places where we have OwnedRef as member variables of classes, so the risk is that an OwnedRef might be destructed at the same time that a PyAcquireGIL lock is being destructed

The PR already takes care of that, by using OwnedRefNoGIL in those places (perhaps I've missed some?).

@pitrou
Copy link
Member Author

pitrou commented Jan 31, 2018

Is it correct to say that now callers must be more careful about acquiring the GIL before making calls into the Python C API (assuming use of OwnedRef)?

The GIL rules for OwnedRef are now the same as they were for ScopedRef. If you're not sure the GIL will remain held at the right times, you can use OwnedRefNoGIL instead.

Copy link
Member

@wesm wesm left a comment

Choose a reason for hiding this comment

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

+1, thanks for doing this, cleaner now!

@wesm wesm closed this in 3098c14 Feb 2, 2018
@pitrou pitrou deleted the ARROW-2052-unify-ownedref-scopedref branch February 2, 2018 13:10
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