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

[Performance regression fix] Fix slowness on proj_trans() on WGS 84 <--> NAD83 conversions #3661

Merged
merged 1 commit into from
Mar 11, 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: 13 additions & 4 deletions src/4D_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ int pj_get_suggested_operation(PJ_CONTEXT *,
!opList[iBest].isPriorityOp)) &&
!alt.isOffshore)) {

if (skipNonInstantiable &&
!proj_coordoperation_is_instantiable(alt.pj->ctx, alt.pj)) {
if (skipNonInstantiable && !alt.isInstantiable()) {
continue;
}
iBest = i;
Expand All @@ -320,6 +319,16 @@ int pj_get_suggested_operation(PJ_CONTEXT *,
return iBest;
}

//! @cond Doxygen_Suppress
/**************************************************************************************/
bool PJCoordOperation::isInstantiable() const {
/**************************************************************************************/
if (isInstantiableCached == INSTANTIABLE_STATUS_UNKNOWN)
isInstantiableCached = proj_coordoperation_is_instantiable(pj->ctx, pj);
return bool(isInstantiableCached);
}
//! @endcond

/**************************************************************************************/
static void warnAboutMissingGrid(PJ *P)
/**************************************************************************************/
Expand Down Expand Up @@ -2100,7 +2109,7 @@ PJ *proj_create_crs_to_crs_from_pj(PJ_CONTEXT *ctx, const PJ *source_crs,
!foundInstanciableAndNonBallpark) {
if (!proj_coordoperation_has_ballpark_transformation(op.pj->ctx,
op.pj) &&
proj_coordoperation_is_instantiable(op.pj->ctx, op.pj)) {
op.isInstantiable()) {
foundInstanciableAndNonBallpark = true;
}
}
Expand Down Expand Up @@ -2432,7 +2441,7 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) {
// If there's just a single coordinate operation which is
// instanciable, use it.
for (const auto &op : P->alternativeCoordinateOperations) {
if (proj_coordoperation_is_instantiable(op.pj->ctx, op.pj)) {
if (op.isInstantiable()) {
if (candidateOp == nullptr) {
candidateOp = op.pj;
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ typedef void (*PJ_OPERATOR)(PJ_COORD &, PJ *);
#define PJD_WGS84 4 /* WGS84 (or anything considered equivalent) */

struct PJCoordOperation {
public:
int idxInOriginalList;
double minxSrc = 0.0;
double minySrc = 0.0;
Expand Down Expand Up @@ -390,6 +391,13 @@ struct PJCoordOperation {
}

~PJCoordOperation() { proj_destroy(pj); }

bool isInstantiable() const;

private:
static constexpr int INSTANTIABLE_STATUS_UNKNOWN =
-1; // must be different from 0(=false) and 1(=true)
mutable int isInstantiableCached = INSTANTIABLE_STATUS_UNKNOWN;
};

enum class TMercAlgo {
Expand Down