The EchoCore.Arrays.LargeMap object provides an associative array implementation that works around Internet-Explorer memory and processing time performance issues. Such issues occur when an associative array in IE6 has elements added and removed frequently. In such cases, IE6 tends to consume additional memory and take longer to perform operations. The following test case demonstrates this issue.
This test case repeatedly adds 1000 elements to an associative array and subsequently removes them. If the "Recreate" box is checked, it will create recreate the entire array between each cycle.
<html>
<head>
<title>Associative Array Memory Test</title>
<script type="text/javascript">
var testMap = new Object();
function test() {
var recreate = document.getElementById("recreate").checked;
var cycles = 20;
var check = false;
var adds = 1000;
var times = new Array();
for (var i = 0; i < cycles; ++i) {
var startTime = new Date().getTime();
for (var j = 0; j < adds; ++j) {
testMap["item_" + i + "_" + j] = "item_" + i + "_" + j;
}
times.push(new Date().getTime() - startTime);
for (var j = 0; j < adds; ++j) {
delete testMap["item_" + i + "_" + j];
}
if (recreate) {
testMap = new Object();
}
if (check) {
var count = 0;
for (var x in testMap) {
++count;
}
document.body.appendChild(document.createTextNode("Count=" + count));
}
}
document.body.appendChild(document.createTextNode("OK:" + recreate + ":" + times));
document.body.appendChild(document.createElement("br"));
window.setTimeout("test();", 200);
}
</script>
<body>
<input type="checkbox" id="recreate">Recreate
<br/>
<a href="javascript:test();">RunTest</a>
<br/>
</body>
</html>
The LargeMap implementation works around this issue by automatically re-creating an associative array once a certain number of elements have been removed from it (250, by default). Testing with the Echo3 500-iteration scripted ghost test yields a 15-20% improvement in performance and significantly reduced memory usage vs. using a conventional associative array. The LargeMap object automatically disables the workaround feature when a browser unaffected by this performance issue is used.