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

Len Kne lkne at houstoneng.com
Thu Jan 13 18:21:46 EST 2011


Hi Jeff

Thanks for the tip and code snippet!  Could you add a wiki entry with this tip?  That will make it more accessible for people to find and make it easier to add to the GeoMOOSE trunk.  The wiki is at: http://www.geomoose.org/wiki/index.php/User_Tips/Code_Snippets

There is a link in the upper right-hand corner to create a logon.

Thanks

Len

From: Jeffrey Schmitz [mailto:jeffreykschmitz at gmail.com]
Sent: Thursday, January 13, 2011 2:08 PM
To: geomoose-users at lists.sourceforge.net
Subject: [Geomoose-users] How we cut our load time in half

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/8aa14d34/attachment.html


More information about the Geomoose-users mailing list