benbovy / spherely

Manipulation and analysis of geometric objects on the sphere.
https://spherely.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
119 stars 8 forks source link

Optimize Python -> C++ Geography conversion #5

Closed benbovy closed 1 year ago

benbovy commented 1 year ago

Partially improves #3

It is not very nice to rely on pybind11 internals but I'm afraid that there's currently no way around that. It's probably worth it given the large gain in performance over directly using pybind11::cast() (almost 10x).

Not sure if it is really safe to use a static class member to store the Geography python type pointer as a cache, but it seems to work. I'll wait adding CI configuration (run tests) in another PR before merging this.

benbovy commented 1 year ago

Not sure if it is really safe to use a static class member to store the Geography python type pointer as a cache

Maybe a cleaner solution would be to store the type in a capsule, e.g., via some init function called just after importing the compiled Python extension (would require installing it as a subpackage).