Jump to content

Recommended Posts

Posted (edited)

After digging deeper into the original reason I reported, http://magicduel.invisionzone.com/topic/16288-always-put-semicolons-at-the-end-of-the-line-in-javascript/, I believe I have found the actual cause of the constant 100% CPU usage with massive memory thrashing.

 

 

In the main page (layout.php), in the <head> tag, there is a reference to:

<script type="text/javascript" src="js/popupinfo.js"></script>

Normally this wouldn't be an issue, but the problem is, that script writes a <div> tag to the document. Because Firefox uses speculative parsing (https://developer.mozilla.org/en-US/docs/Web/HTML/Optimizing_your_pages_for_speculative_parsing), this causes the entire document to be re-parsed.

 

 

Note: Everything after this point is informed speculation. Due to the fact it's impossible to disable speculative parsing in Firefox, I cannot be certain that this is in-fact the cause of the issue.

 

Normally this wouldn't be much of an issue, as it's just a single re-parse (admittedly it uses 100mb of RAM to do the re-parse), but the problem comes in when we bring the chat into the picture. The chat refreshes every 5 seconds, and, every time it does so, it modifies the DOM, and, if the document is in the middle of the re-parse from the earlier issue, the entire document will be re-parsed again, from the start. But wait, there's more! It's been another 5 seconds, so we're updating the chat again! This causes the document to once again start re-parsing, and the issue continues.

 

 

I believe that the solution to this issue is to simply move the <script> tag referenced above out of the <head> tag, and into the <body> tag, as the document.write would be a balanced write, which would no longer cause the initial re-parse, and eliminate the cascading effect that caused the CPU and memory usage issues.

Edited by I am Bored
  • Root Admin
Posted

Thanks for looking into debugging this bored, I think you might be right there :)

also: https://www.youtube.com/watch?v=omD3m-xwBWk

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Forum Statistics

    17.5k
    Total Topics
    182.1k
    Total Posts
  • Recently Browsing

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...