Timer fired every 100ms if you add a facebook like button
Asked Answered
T

2

6

I have noticed that Facebook's XFBML like button adds a timer that triggers every 100ms. Does anyone knows why? Also, is it possible to remove this timer?

I think this is a bug because 100ms means it fired very often. Also, if you have 10 like buttons you will have 10 triggers fired every 100ms, 100 triggers per second. That's a lot and can causes some performance problems.

You can check this in Chrome by opening: http://mashable.com/ (they have a lot of like buttons) Then just open developers tools and from timeline tab do a record. You will see a lot of Timer fired (see snapshot http://cl.ly/272h3V1u1t3w0f1R4625).

Tyler answered 8/12, 2011 at 11:5 Comment(1)
First time I see this bug. That thing should not be a problem using iframe like button. Even if it can make trouble, I don't think having 10 likes in a page could be good. And BTW performance depends on what does the process do, not the timing.Motionless
M
3

Looks to me as if each like button sets up it's own polling to keep updated instead of setting up a small pubsub architecture where it only has one timer polling and alerting any subscribers.

So I'd simply discard this as a bad implementation on facebooks part and take it up with them to rewrite it.

Pubsub is really not that difficult to implement. Just take a look at this implementation: https://github.com/daniellmb/MinPubSub

Megdal answered 9/12, 2011 at 14:14 Comment(0)
M
0

Munter is correct. To make things worse, each timer fired also results in a rather large amount of JavaScript objects and DOM elements being created. This causes garbage collection to run wild, which has some very adverse effects on user experience: e.g. animations (both CSS-based and JS-based) will start stuttering and interactions dependent on real-time response to user input become jerky or unresponsive. (Firefox in particular seems to suffer here.)

To top things off, each timed execution also queries the DOM for rendered element dimensions and causes repaints.

Monroe answered 12/7, 2012 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.