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

PERF: drop GIL during long-running proj database calls #1354

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,15 @@ cdef PJ* proj_create_crs_to_crs(
ELSE:
raise NotImplementedError("only_best requires PROJ 9.2+.")


cdef PJ* transform = proj_create_crs_to_crs_from_pj(
ctx,
source_crs,
target_crs,
area,
options,
)
cdef PJ* transform = NULL
with nogil:
transform = proj_create_crs_to_crs_from_pj(
tpwrules marked this conversation as resolved.
Show resolved Hide resolved
ctx,
source_crs,
target_crs,
area,
options,
)
proj_destroy(source_crs)
proj_destroy(target_crs)
if transform == NULL:
Expand Down
48 changes: 29 additions & 19 deletions pyproj/database.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def get_authorities():
Authorities in PROJ database.
"""
cdef PJ_CONTEXT* context = pyproj_context_create()
cdef PROJ_STRING_LIST proj_auth_list = proj_get_authorities_from_database(context)
cdef PROJ_STRING_LIST proj_auth_list = NULL
with nogil:
proj_auth_list = proj_get_authorities_from_database(context)
if proj_auth_list == NULL:
pyproj_context_destroy(context)
return []
Expand Down Expand Up @@ -108,14 +110,19 @@ def get_codes(str auth_name not None, pj_type not None, bint allow_deprecated=Fa
cdef PJ_CONTEXT* context = NULL
cdef PJ_TYPE cpj_type = get_pj_type(pj_type)
cdef PROJ_STRING_LIST proj_code_list = NULL
cdef const char* c_auth_name = NULL
cdef bytes b_auth_name
try:
context = pyproj_context_create()
proj_code_list = proj_get_codes_from_database(
context,
cstrencode(auth_name),
cpj_type,
allow_deprecated,
)
b_auth_name = cstrencode(auth_name)
c_auth_name = b_auth_name
with nogil:
proj_code_list = proj_get_codes_from_database(
context,
c_auth_name,
cpj_type,
allow_deprecated,
)
finally:
pyproj_context_destroy(context)
if proj_code_list == NULL:
Expand Down Expand Up @@ -239,11 +246,12 @@ def query_crs_info(
query_params.east_lon_degree = area_of_interest.east_lon_degree
query_params.north_lat_degree = area_of_interest.north_lat_degree

crs_info_list = proj_get_crs_info_list_from_database(
context,
c_auth_name,
query_params,
&result_count)
with nogil:
crs_info_list = proj_get_crs_info_list_from_database(
context,
c_auth_name,
query_params,
&result_count)
finally:
if query_params != NULL:
proj_get_crs_list_parameters_destroy(query_params)
Expand Down Expand Up @@ -400,13 +408,15 @@ def get_units_map(str auth_name=None, str category=None, bint allow_deprecated=F

cdef int num_units = 0
cdef PJ_CONTEXT* context = pyproj_context_create()
cdef PROJ_UNIT_INFO** db_unit_list = proj_get_units_from_database(
context,
c_auth_name,
c_category,
bool(allow_deprecated),
&num_units,
)
cdef PROJ_UNIT_INFO** db_unit_list = NULL
with nogil:
db_unit_list = proj_get_units_from_database(
context,
c_auth_name,
c_category,
bool(allow_deprecated),
Copy link
Member

Choose a reason for hiding this comment

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

I am surprised cython didn't complain about using bool with nogil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm assuming it's valid if it did not complain, but I'm not 100% sure.

&num_units,
)
units_map = {}
try:
for iii in range(num_units):
Expand Down