PDA

View Full Version : Cross Browser marquee II - causes unusually high CPU usage in firefox



zorba
02-18-2009, 11:59 PM
1) Script Title:
Cross Browser marquee II

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex2/cmarquee2.htm

3) Describe problem:

When I view the marquee in IE it works just fine but when I view it in firefox it degrades the performance of my PC.

Using TaskManager > Processes I can see that firefox.exe is now taking approx on average 30-35% of the CPU time.

When I move the mouse over the marquee to pause the marquee scrolling, after a second or two the CPU %age for firefox drops to 0. Then if I mouse away and scrolling starts again, the CPU usage rises again to the previous level.

I am using Firefox 3.0.6 on XP Home SP3.
1.35GHz AMD Athlon CPU and 448MB RAM.

(NB I first discovered this problem as our website was coded by a webdesigner a few years ago using a version of this marquee, and when we moved to firefox last month I noticed CPU usage went to nearly 90% when the marquee scrolled, and everything else was totally killed. See www.altmore.co.uk. I got a shock when I found your site and firefox was struggling here too, though not as much as with our site - maybe the amount of text were putting through it might be a factor ?

PS this could explain the problems ppl have with firefox viewing flash on the same page as the marquee, as flash is also processor hungry)

By the way, thanks for providing all this stuff!

Snookerman
02-19-2009, 05:34 AM
It doesn't do it for me, it stays at 00 all the time.

zorba
02-19-2009, 08:18 PM
in firefox ?

what version are you running?
also, what is the spec of your PC?
That might have something to do with it...

And were you running other programs, or just your browser?

Snookerman
02-19-2009, 08:25 PM
Fx 3.0.6 XP SP3 Intel 2.8 GHz 2 Gb RAM

I was just running some basic programs, photoshop, word, etc.

zorba
02-20-2009, 12:05 PM
on my work PC (which is slightly higher spec than my home PC) I can reproduce this also, but at average of approx 25% of CPU usage - which is still way above what it should be.... (drops to 0-2% when scrolling paused)

spec =
firefox 3.0.6, XP Pro SP3
2.53GHz Celeron CPU, 1.99GB of RAM

i.e. very similar spec to Snookerman, but an AMD processor, not Intel !
Also, my home PC has an AMD processor

Hmm, is there a pattern here ?
I've heard that AMD's don't have a maths co-processor so not so good for graphics, gaming etc. (which I'm not into, so not bothered), but maybe the way Firefox is rendering this scroller makes heavy use of graphics/maths routines, and AMD's can't keep up ?

Anyone else with an AMD chip, or lower spec machine able to reproduce this ?

And, Is there some other way to implement this component so it doesn't make so many graphics/maths calls in firefox ?

many thanks!

karoli
05-08-2009, 07:28 PM
Same thing is happening for me! Glad you posted this, because I really wondered what was going on!

What is the work around? I have to solve this fast, maybe rewrite as a Flash component instead of using the marquee II

Thanks

zorba
06-25-2009, 01:48 PM
I came back to this as its very annoying and still not sorted !!

It might be a bug in FF, see:
https://bugzilla.mozilla.org/show_bug.cgi?id=442797

While they get round to (maybe) fixing it, can anyone suggest a work-around?
don't know enought about javascript (yet) myself to fix it :-(

zorba
06-25-2009, 02:12 PM
I added it as a FF bug (to bugzilla)

Bug 500410

https://bugzilla.mozilla.org/show_bug.cgi?id=500410

Anyone who can reproduce it, or shed any light on it, might want to post on bugzilla (not sure what the protocol is, so please check first) as well as here!

Abroz
07-04-2009, 12:33 AM
A work-around was posted in the bug as
https://bugzilla.mozilla.org/attachment.cgi?id=385508 with the javascript moved with the content into an iframe ( https://bugzilla.mozilla.org/attachment.cgi?id=385507 ) that simply scrolls itself, no CSS reflow happens then, which is referred to in comments as https://bugzilla.mozilla.org/show_bug.cgi?id=502288 and https://bugzilla.mozilla.org/show_bug.cgi?id=479655 - the fixes to which will likely only appear in the next *major* update of Firefox sometime within the next couple of years, so go with the work-around.

Abroz
07-04-2009, 03:37 AM
Clearly the code could use a tweak to break out of the iFrame whenever a link is clicked on. Here's the adjusted initializemarquee function:


function initializemarquee(){
var ah = document.getElementsByTagName("a");
for (var b=0;b<ah.length;b++) {
ah[b].setAttribute("onclick","top.location = this.href")
}
cross_marquee=document.getElementById("vmarquee");
cross_marquee.style.top=0;
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}

Abroz
07-04-2009, 03:44 AM
Okay the above code breaks out of the iFrame on every browser except IE. Anyone know how to break out of an iFrame in IE?

Abroz
07-04-2009, 04:33 AM
Revised with the additional hacks needed for IE:


function initializemarquee(){
var ah = document.getElementsByTagName("a");
for (var b=0;b<ah.length;b++) {
ah[b].setAttribute("onclick","top.location = this.href")
if (ah[b].attachEvent) { ah[b].attachEvent("onclick", breakout) }
}
cross_marquee=document.getElementById("vmarquee");
cross_marquee.style.top=0;
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}
function breakout() {
top.location = window.event.srcElement.href
}


This is just altering part of the code that is in https://bug500410.bugzilla.mozilla.org/attachment.cgi?id=385507

Let me know if you need further help.