I am banging my head against the wall with this one. I have written an AJAX call and inside the success event I process the data in a for loop. The length of the data is capped at 10000 records. The first time the process flies through the loop. I've added a timer and every hundred records are processed in 6ms to 24ms. This is 1ms when I comment out the OpenLayer 3.5 calls.
Then I run the same process again. The dataset is exactly the same as in the first run. Now every hundred records are processed in 250ms to 2600ms until after a few hundred records the loop crashes when the Openlayers library stops responding. Again, with the OpenLayers functions commented as in the code below the process speeds through the loop as before.
I am not sure whether this is an issue with the OpenLayers library or how I call the functions from that library in my loop.
Any help or tips are welcome.
function (data) { var statsSOABuffer = { km15: { y2005: 0, y2006: 0, y2007: 0, y2008: 0, y2009: 0, y2010: 0, y2011: 0, y2012: 0, y2013: 0, y2014: 0, y2015: 0, count: 0 }, km30: { y2005: 0, y2006: 0, y2007: 0, y2008: 0, y2009: 0, y2010: 0, y2011: 0, y2012: 0, y2013: 0, y2014: 0, y2015: 0, count: 0 }, km45: { y2005: 0, y2006: 0, y2007: 0, y2008: 0, y2009: 0, y2010: 0, y2011: 0, y2012: 0, y2013: 0, y2014: 0, y2015: 0, count: 0 } }; var checkT = new Date().getTime(); var n = data.length; for (i = 0; i < n; i++) { var record = data; if ((i % 100) == 0) { var curT = new Date().getTime(); console.log(i + ' / ' + n + ' T:' + (curT - checkT)); checkT = curT; } //var feature = new ol.Feature( // new ol.geom.Point( // ol.proj.transform([record[13], record[14]], 'EPSG:27700', 'EPSG:3857') // ) //); //feature.setProperties({ // distance: record[1], // jsa2015: record[12] * 2 //}); //sourceSOABuffer.addFeature(feature); switch (true) { case (record[1] < 15000): statsSOABuffer.km15.y2005 += record[2]; statsSOABuffer.km15.y2006 += record[3]; statsSOABuffer.km15.y2007 += record[4]; statsSOABuffer.km15.y2008 += record[5]; statsSOABuffer.km15.y2009 += record[6]; statsSOABuffer.km15.y2010 += record[7]; statsSOABuffer.km15.y2011 += record[8]; statsSOABuffer.km15.y2012 += record[9]; statsSOABuffer.km15.y2013 += record[10]; statsSOABuffer.km15.y2014 += record[11]; statsSOABuffer.km15.y2015 += (2 * record[12]); statsSOABuffer.km15.count += 1; break; case (record[1] < 30000): statsSOABuffer.km30.y2005 += record[2]; statsSOABuffer.km30.y2006 += record[3]; statsSOABuffer.km30.y2007 += record[4]; statsSOABuffer.km30.y2008 += record[5]; statsSOABuffer.km30.y2009 += record[6]; statsSOABuffer.km30.y2010 += record[7]; statsSOABuffer.km30.y2011 += record[8]; statsSOABuffer.km30.y2012 += record[9]; statsSOABuffer.km30.y2013 += record[10]; statsSOABuffer.km30.y2014 += record[11]; statsSOABuffer.km30.y2015 += (2 * record[12]); statsSOABuffer.km30.count += 1; break; case (record[1] < 45000): statsSOABuffer.km45.y2005 += record[2]; statsSOABuffer.km45.y2006 += record[3]; statsSOABuffer.km45.y2007 += record[4]; statsSOABuffer.km45.y2008 += record[5]; statsSOABuffer.km45.y2009 += record[6]; statsSOABuffer.km45.y2010 += record[7]; statsSOABuffer.km45.y2011 += record[8]; statsSOABuffer.km45.y2012 += record[9]; statsSOABuffer.km45.y2013 += record[10]; statsSOABuffer.km45.y2014 += record[11]; statsSOABuffer.km45.y2015 += (2 * record[12]); statsSOABuffer.km45.count += 1; } }
أكثر...
Then I run the same process again. The dataset is exactly the same as in the first run. Now every hundred records are processed in 250ms to 2600ms until after a few hundred records the loop crashes when the Openlayers library stops responding. Again, with the OpenLayers functions commented as in the code below the process speeds through the loop as before.
I am not sure whether this is an issue with the OpenLayers library or how I call the functions from that library in my loop.
Any help or tips are welcome.
function (data) { var statsSOABuffer = { km15: { y2005: 0, y2006: 0, y2007: 0, y2008: 0, y2009: 0, y2010: 0, y2011: 0, y2012: 0, y2013: 0, y2014: 0, y2015: 0, count: 0 }, km30: { y2005: 0, y2006: 0, y2007: 0, y2008: 0, y2009: 0, y2010: 0, y2011: 0, y2012: 0, y2013: 0, y2014: 0, y2015: 0, count: 0 }, km45: { y2005: 0, y2006: 0, y2007: 0, y2008: 0, y2009: 0, y2010: 0, y2011: 0, y2012: 0, y2013: 0, y2014: 0, y2015: 0, count: 0 } }; var checkT = new Date().getTime(); var n = data.length; for (i = 0; i < n; i++) { var record = data; if ((i % 100) == 0) { var curT = new Date().getTime(); console.log(i + ' / ' + n + ' T:' + (curT - checkT)); checkT = curT; } //var feature = new ol.Feature( // new ol.geom.Point( // ol.proj.transform([record[13], record[14]], 'EPSG:27700', 'EPSG:3857') // ) //); //feature.setProperties({ // distance: record[1], // jsa2015: record[12] * 2 //}); //sourceSOABuffer.addFeature(feature); switch (true) { case (record[1] < 15000): statsSOABuffer.km15.y2005 += record[2]; statsSOABuffer.km15.y2006 += record[3]; statsSOABuffer.km15.y2007 += record[4]; statsSOABuffer.km15.y2008 += record[5]; statsSOABuffer.km15.y2009 += record[6]; statsSOABuffer.km15.y2010 += record[7]; statsSOABuffer.km15.y2011 += record[8]; statsSOABuffer.km15.y2012 += record[9]; statsSOABuffer.km15.y2013 += record[10]; statsSOABuffer.km15.y2014 += record[11]; statsSOABuffer.km15.y2015 += (2 * record[12]); statsSOABuffer.km15.count += 1; break; case (record[1] < 30000): statsSOABuffer.km30.y2005 += record[2]; statsSOABuffer.km30.y2006 += record[3]; statsSOABuffer.km30.y2007 += record[4]; statsSOABuffer.km30.y2008 += record[5]; statsSOABuffer.km30.y2009 += record[6]; statsSOABuffer.km30.y2010 += record[7]; statsSOABuffer.km30.y2011 += record[8]; statsSOABuffer.km30.y2012 += record[9]; statsSOABuffer.km30.y2013 += record[10]; statsSOABuffer.km30.y2014 += record[11]; statsSOABuffer.km30.y2015 += (2 * record[12]); statsSOABuffer.km30.count += 1; break; case (record[1] < 45000): statsSOABuffer.km45.y2005 += record[2]; statsSOABuffer.km45.y2006 += record[3]; statsSOABuffer.km45.y2007 += record[4]; statsSOABuffer.km45.y2008 += record[5]; statsSOABuffer.km45.y2009 += record[6]; statsSOABuffer.km45.y2010 += record[7]; statsSOABuffer.km45.y2011 += record[8]; statsSOABuffer.km45.y2012 += record[9]; statsSOABuffer.km45.y2013 += record[10]; statsSOABuffer.km45.y2014 += record[11]; statsSOABuffer.km45.y2015 += (2 * record[12]); statsSOABuffer.km45.count += 1; } }
أكثر...