Open Bug 669071 Opened 10 years ago Updated 2 years ago

createElement freezes browser, utilizes 100% CPU and sucks up memory fast

Categories

(Core :: DOM: Core & HTML, defect, P5)

5 Branch
x86_64
Windows Server 2003
defect

Tracking

()

UNCONFIRMED

People

(Reporter: jab_creations, Unassigned)

Details

(Keywords: perf, testcase)

Attachments

(1 file)

While working on a contenteditable element trying to force text in to paragraph elements due to bug 662591 I apparently commented out the removeChild method while not commenting out the createElement method.

Here is the following function that is triggered on the keyup event...
----------------
function editor_paragraph_gecko_bug(e)
{
 var a = '';
 var b = document.getElementById('editor_test');
 var n = b.childNodes;

 for (var i=0;i<n.length;i++)
 {
  if (n[i].nodeValue)
  {
   if (n[i].nodeValue.length>0)
   {
    var p = document.createElement('p');
    var t = document.createTextNode(n[i].nodeValue);
    //p.appendChild(t);

    //b.insertBefore(p,n[i]);
    //b.removeChild(n[i].b.childNodes[i]);

    //a += n[i]+' = ['+i+'] = '+n[i].nodeValue+' = length = '+n[i].nodeValue.length+'\n';
   }
   else
   {
    a += n[i]+'\n';
   }
  }
  else {a += n[i]+'\n';}
 }

 document.getElementById('test1').value=a;
 //window.getSelection().focusNode.parentNode
}
----------------

This led to one CPU core being completely and unrelentingly utilized at 100% while my RAM usage quickly and steadily increased. It effectively forced me to close Firefox (though I did not have to kill it via the task manager at least).

There should be some mechanism that prevents this, the manner of doing so is subjective to debate. I think a full error (not warning) should be added to the console and a certain limit set in the browser in the very least.
Could you attach a test with un-commented script so I can test it live?
I guess you end up in an infinite loop? Did you get the slow scrip dialog?
I reconstructed a basic bare-bones example however I can't seem to replicate the issue at this time. I've since edited the original extensively since I discovered the bug past the extent that I am able to replicate the bug with that file.
Mozilla/5.0 (Windows NT 6.1; rv:7.0a1) Gecko/20110704 Firefox/7.0a1

> This led to one CPU core being completely and unrelentingly utilized at 100%
> while my RAM usage quickly and steadily increased. It effectively forced me
> to close Firefox (though I did not have to kill it via the task manager at
> least).

Loading the attached example in Firefox Nightly (7.0a1)I get the following loads:
CPU: usage -> 0; threads -> 27
Memory: Commit -> 94 MB; Working set -> 112 MB; Private -> 70 MB
So, none of these seem odd. 

Could you provide more details regarding the config (OS, browser version)? Is it Fx5 and Windows Server? Thanks
I'm using 64 Bit XP Pro and Firefox 5.0 stable.

I think it's code related than platform related (though I can't verify that without being able to replicate it). Offhand I think the combination of double nested for loops (to nest through blockquote elements and then for each blockquote to loop through childNodes in example) while attempting to alert (or write the returned value to a textarea for visual analysis) may trigger this too as there was a single time where I encountered Firefox freezing up (after a script timeout notification) however I was unable to replicate that using the same code (and it did not add to memory unlike the first issue I encountered). When I encounter something I can reproduce I'll make a copy, minimize the code and post it as an attachment.
modest CPU usage, but not high memory using current nightly on vista
Severity: major → normal
Keywords: perf, testcase
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven't been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.