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.

Always put semicolons at the end of the line in javascript

Featured Replies

After noticing that Firefox was using 25% CPU almost constantly with MD open (Opera uses 0-3%), I did a bit of digging. I noticed that updatetime was taking most of the time. Naturally, I went to look at the function. It has nothing that should be nearly that expensive. I then noticed by complete chance that there were no semicolons at the end of the line. Wondering if this could, for some absurd reason, be the cause, I promptly re-defined the functions to be semi-colon terminated. No sooner had I done that than the CPU usage (and absurd amount of memory allocation thrashing) disappeared. 

 

The morale of the story? Always terminate your statements in Javascript with semicolons, because, although it will still work in most browsers, you never know how a browser will handle it.

 

 

The pair of functions, with semicolons added:

function padlength(what){

    var output=(what.toString().length==1)? "0"+what : what;

    return output;

}



function displaytime(){

    serverdate.setSeconds(serverdate.getSeconds()+1);

    var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate()); //+", "+serverdate.getFullYear()

    var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds());

    document.getElementById("servertime").innerHTML=datestring+" "+timestring;//datestring+" "+

}
  • Root Admin

Im unconvinced that this is the issue. Semi colons at the end of a line is not required in javascript as it will tokenize the newline.

I think your combined efforts of hacking around MD has finally got to your browser. I have told you bored that if you are modifying MD I dont want your reports because then you are running some custom thing that I cannot debug.

I will eventually get around to cleaning that up but I think there is no evidence to say it has any effect on CPU time.

  • Author

After some more testing, the fix applied seams to have no effect at all, yet it worked as-described this morning. It looks like I'll have to do some more digging to figure this issue out.

 

The CPU usage difference is present though.

I think your combined efforts of hacking around MD has finally got to your browser. I have told you bored that if you are modifying MD I dont want your reports because then you are running some custom thing that I cannot debug.

This is just mean and you know it. We all know that MD is filled with bugs. Lets see how IaB explains / prove it.

 

I too have some issues with MD. When it is running too long I have to refresh the page to make it run smoother.

But I've always attributed this to the flash usage.

  • Root Admin

This is just mean and you know it. We all know that MD is filled with bugs. Lets see how IaB explains / prove it.
 
I too have some issues with MD. When it is running too long I have to refresh the page to make it run smoother.
But I've always attributed this to the flash usage.


We are talking about it on yim, he has been bombarding me with him hacking apart MD.

If we can see some stats, I will implement the changes sooner than planned, but I dont see any reason for it to make a difference due to how it works.

also: https://www.youtube.com/watch?v=WGoi1MSGu64

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.