This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
stripCustomNsAttrs performance #14928
Closed
Description
Performance suggestion
stripCustomNsAttrs is currently using recursive to walk the siblings in the DOM tree, which can easily cause it to run out of stack space in Internet Explorer. That happens to us when sanitizing a string containing cca 3000 DOM elements (which we do as performance optimization over ng-repeat, normally we of course bind much smaller strings).
It seems rewriting the code to use iteration should be safe, and resolves the problem entirely:
function stripCustomNsAttrs(node) {
while(node) {
if (node.nodeType === window.Node.ELEMENT_NODE) {
var attrs = node.attributes;
for (var i = 0, l = attrs.length; i < l; i++) {
var attrNode = attrs[i];
var attrName = attrNode.name.toLowerCase();
if (attrName === 'xmlns:ns1' || attrName.lastIndexOf('ns1:', 0) === 0) {
node.removeAttributeNode(attrNode);
i--;
l--;
}
}
}
var nextNode = node.firstChild;
if (nextNode) {
stripCustomNsAttrs(nextNode);
}
node = node.nextSibling;
}
}
We experience the issue in Angular 1.5.7, Internet Explorer 11. The string bound is something like
<div class="entry"><div class="icon icontype"></div><span>Name</span></div>
repeated 3000x