Permalink
Browse files

msDrawMap(): optimize pre-processing of WMS/WFS layers

Currently we use msLayerIsVisible() to determine how many potential WMS/WFS
layers there are. But this is a costly operation. Rather test the connectiontype,
and defer testing msLayerIsVisible() as late as possible.
  • Loading branch information...
rouault committed Oct 12, 2017
1 parent 35b82b9 commit 226d19a6fe68ac1e0f19cc3a593841e3da54ce22
Showing with 22 additions and 15 deletions.
  1. +22 −10 mapdraw.c
  2. +0 −5 maphttp.c
View
@@ -220,7 +220,8 @@ imageObj *msDrawMap(mapObj *map, int querymap)
#if defined(USE_WMS_LYR) || defined(USE_WFS_LYR)
enum MS_CONNECTION_TYPE lastconnectiontype;
httpRequestObj *pasOWSReqInfo=NULL;
int numOWSLayers=0, numOWSRequests=0;
int numOWSLayers=0;
int numOWSRequests=0;
wmsParamsObj sLastWMSParams;
#endif
@@ -256,30 +257,43 @@ imageObj *msDrawMap(mapObj *map, int querymap)
*/
numOWSLayers=0;
for(i=0; i<map->numlayers; i++) {
if(map->layerorder[i] != -1 &&
msLayerIsVisible(map, GET_LAYER(map,map->layerorder[i])))
if(map->layerorder[i] == -1 )
continue;
lp = GET_LAYER(map,map->layerorder[i]);
if( lp->connectiontype != MS_WMS &&
lp->connectiontype != MS_WFS ) {
continue;
}
numOWSLayers++;
}
if (numOWSLayers > 0) {
/* Alloc and init pasOWSReqInfo...
*/
pasOWSReqInfo = (httpRequestObj *)malloc((numOWSLayers+1)*sizeof(httpRequestObj));
pasOWSReqInfo = (httpRequestObj *)malloc(numOWSLayers*sizeof(httpRequestObj));
if (pasOWSReqInfo == NULL) {
msSetError(MS_MEMERR, "Allocation of httpRequestObj failed.", "msDrawMap()");
return NULL;
}
msHTTPInitRequestObj(pasOWSReqInfo, numOWSLayers+1);
msHTTPInitRequestObj(pasOWSReqInfo, numOWSLayers);
msInitWmsParamsObj(&sLastWMSParams);
/* Pre-download all WMS/WFS layers in parallel before starting to draw map */
lastconnectiontype = MS_SHAPEFILE;
for(i=0; numOWSLayers && i<map->numlayers; i++) {
if(map->layerorder[i] == -1 || !msLayerIsVisible(map, GET_LAYER(map,map->layerorder[i])))
for(i=0; i<map->numlayers; i++) {
if(map->layerorder[i] == -1 )
continue;
lp = GET_LAYER(map,map->layerorder[i]);
if( lp->connectiontype != MS_WMS &&
lp->connectiontype != MS_WFS ) {
continue;
}
if( !msLayerIsVisible(map, lp) )
continue;
#ifdef USE_WMS_LYR
if(lp->connectiontype == MS_WMS) {
@@ -306,9 +320,7 @@ imageObj *msDrawMap(mapObj *map, int querymap)
lastconnectiontype = lp->connectiontype;
}
#ifdef USE_WMS_LYR
msFreeWmsParamsObj(&sLastWMSParams);
#endif
} /* if numOWSLayers > 0 */
if(numOWSRequests && msOWSExecuteRequests(pasOWSReqInfo, numOWSRequests, map, MS_TRUE) == MS_FAILURE) {
View
@@ -113,11 +113,6 @@ void msHTTPCleanup()
* Should be called on a new array of httpRequestObj to initialize them
* for use with msHTTPExecuteRequest(), etc.
*
* Note that users of this module should always allocate and init one
* more instance of httpRequestObj in their array than what they plan to
* use because the terminate_handler() needs the last entry in the array
* to have reqObj->request == NULL
*
**********************************************************************/
void msHTTPInitRequestObj(httpRequestObj *pasReqInfo, int numRequests)
{

0 comments on commit 226d19a

Please sign in to comment.