[Mapserver-dev] Speed Increase #2 of the day

Alan Steremberg alans at wunderground.com
Thu Nov 6 14:55:22 EST 2003


The label cache does some kind of polygon checking to see if labels
intersect before drawing them.

I profiled the code using one of my hairy map examples where I was drawing
130,000 street lines, and a bunch of city labels, etc.  In my case, I
found that 99% of the time the two polygon's weren't intersecting. This is
the worst case scenario for the code:

intersectLabelPolygons

I was able to greatly increase my performance by adding this check to the
top of the code:

    /* AJS - alans at wunderground.com */
    /* STEP 0: check bounding boxes */
    msComputeBounds(p1);
    msComputeBounds(p2);
    if (!msRectOverlap(&p1->bounds, &p2->bounds))
    {
        return MS_FALSE;
    }


It checks the quick to calculate case of are the bounding boxes
overlapping, if not, let's get out of here quickly.  I was thinking about
investigating fancy polygon overlap strategies (scanning, etc??) but this
made my crazy map with 200,000 items on it draw really quickly, so I
figured I was done for now.

This took my example from 0.21 sec to 0.09 sec. seems good.

I will keep profiling.. I replaced the truetype font code with bitmap code
that rotates, seems to be a lot faster if you want a lot of labels on the
map.  The code still needs some work, but I would be happy to contribute
it once it is done. In the process we found that at certain angles GD TTF
doesn't return the correct bounding boxes.. That is why text sometimes
bumps into each other.

----------------------------
 Alan Steremberg
 415-543-5021 x 103
 http://www.wunderground.com



More information about the mapserver-dev mailing list