Skip to content
View in the app

A better way to browse. Learn more.

MagicDuel Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

MD is not Speculative Parsing Friendly

Featured Replies

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

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...

Forum Statistics

  • Total Topics 17.5k
  • Total Posts 182.2k

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.