[Geomoose-users] How we cut our load time in half

Jeffrey Schmitz jeffreykschmitz at gmail.com
Thu Jan 13 15:08:10 EST 2011


Hey Everyone,

I'm not sure if this is the best place to post this, so please let me know
if there is a better place to send it. Anyways, we were able to cut our page
load time in half for our geomoose instance, and I thought I'd post it on
the mailing list in case it might help someone else out. Using firebug, we
were able to determine that Geomoose's itereateThroughLayers function was
taking a significant amount of time, so we looked for a way to improve it.
We ended up coming up with a solution that is slightly more memory
intensive, but cut the time spent on the function in half. To implement the
change, just replace the old iterateThroughLayers function with the
following code (in compiled.js):

    var theLayer = new Array();
    var pathsP = new Array();
    function iterateThroughLayers(pathString, fn) {
        if(pathsP[pathString] == null){
        var services = MyCatalog.getElementsByTagName('map-source');
        var paths = new String(pathString).split(':');
        for(var i = 0; i < services.length; i++) {
            var root = services[i].getAttribute('name');
            var layers = services[i].getElementsByTagName('layer');
            for(var l = 0; l < layers.length; l++) {
                var layerName = layers[l].getAttribute('name')
                for(var p = 0; p < paths.length; p++) {
                    if(root+'/'+layerName == paths[p]) {
                        var mapLayer = Map.getLayersByName(root)[0];
                        theLayer[pathString] = mapLayer;
                        pathsP[pathString] = paths[p];
                        if(mapLayer) {
                            fn(mapLayer, paths[p]);
                        }
                    }
                }

            }
        }
        }
        else{
            if(theLayer[pathString]){
                fn(theLayer[pathString], pathsP[pathString]);
            }
        }

    }

This works because the function is hit twice with the same pathString (just
a different function), and unnecessarily has to run through the same series
of identical loops twice. Instead, the information genorated from the first
run through is stored in the two arrays theLayer and pathsP and recalled.

This may not significantly improve speeds if you are not using many layers,
but if you are, you should see some gains. I hope this helps some people
out!

-Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geomoose-users/attachments/20110113/21c9e37b/attachment.html


More information about the Geomoose-users mailing list