Wednesday, February 25, 2009

3,500 collectors on Colnect

Yesterday Colnect has passed the mark of 3,500 registered collectors. This is an increase of over 17% during the last 2 months. Just before starting this year, Colnect had passed the 3,000 collectors mark. Considering the fact that ridiculously little marketing work has been done (~$50 spent on ads...), I see this as a very respectable achievement that continues the growth that started when Colnect V2 was released.

How do collectors learn about Colnect?


As Colnect allows collectors to manage their personal collection and semi-automatically manage swaps with other collectors from around the world, it's the collectors' own interest to have their collector friends join the site. Why would a collector go through the swap and wish lists of another collector manually when a match to his own lists can be done using a single click?

So what's next?


Colnect will expand to more collectible fields as requests come from existing members of the community. Some requested premium services are also planned.

Thursday, February 19, 2009

BE CAREFUL when using both AdSense + AdWords by Google


Do you have a website and using both AdSense and AdWords? If so, this post will interest you. You may start by looking at the attached picture.

AdWords and AdSense are the different sides of the same coin and Google is in the middle, biting on the metal. AdSense allows website owners to show different ads from different advertisers on their website and receive revenues for it. AdWords allow you to advertise your website on many other websites running AdSense. Google takes its commission for providing both these services. Though many other competing programs exist on the web, Google's generally have good reputation.

Advertising my site on my site?!?!?!


This morning, I was amazed to see an ad to my website for collectors on the same site! Had I clicked this ad, my AdWords account would have been billed for the click while my AdSense account would have received some revenue. Obviously the latter would be lesser since Google get their cut. This is, of course, ridiculous and should be automatically prevented by Google. Apparently, it isn't. Just to ensure you that I'm not an idiot, the ad is for colnect.com and the website is on the same domain - colnect.com

I usually view my own site with ads disabled so I don't accidentally click an ad and violate the terms of service. This time I was at a friend's house and am quite happy to have stumbled upon the aforementioned bug/feature.

Quick Remedy




Both accounts allow you to use filters and I've now added "competition filters" for my AdSense account that will prevent showing ads for any of my domain. It's also possible to filter out sites on AdWords but this can seemingly be done only on the campaign level so if you're running many different campaigns, it'll become tedious. See the attached pictures.

Saturday, February 14, 2009

Upto 80% Speed Increase on Colnect with Symfony

I have managed to cut up to 80% in loading times for Colnect's pages. This is going to be a technical post that would hopefully help others using Symfony framework on their websites. Please mind that for many sites, caching can and should be enabled. On Colnect, however, a lot of pages (especially the heavy ones) cannot be cached since they need be calculated on every request from the same user. If your site is not very dynamic, using APC (if you have a single server) or memcached (when you have many) is the best thing you can do for performance.

Partials are evil


Maybe not that evil but they take their toll on your loading time. The worst is when using them inside a loop as the price increases linearly. Use helpers whenever possible but make sure you load only the necessary helpers on each call and don't try to re-load helpers when inside a loop.

Re-use function results


Symfony encourages you to use methods and functions repeatedly, for example sfContext::getInstance()->getModuleName();. Obviously, the more calculations, the longer things take so whenever you need to re-use results, save the variable content.

A good PHP structure for re-using results is:

function foo_calculate() {
static $result = null;
if (is_null($result)) {
# perform calculations
$result = calculation results...
}
return $result;
}


Escaping PHP and going back to PHP takes its toll


Using
?>xxx
is more costly than
echo 'xxx';
See code on the next paragraph.

Using many echo calls slows things down



It's better to accumulate output in a variable and call a single echo.
The following code performs simple tests so you can get a feeling of the differences in execution times. Run it a few times (when all other applications are closed) since results alter a bit every time.


public function executeCompareOutput(sfWebRequest $request) {
$times = 100000;
echo 'Looping for '.$times.' times - results in msec';
echo '<-div style="display:none">';
$start = microtime(true);
for ($x = 0; $x++ < $times;) {
echo ' '.$x;
}
echo '<-/div><-br/>'.round(1000 * (microtime(true) - $start));

$start = microtime(true);
echo '<-div style="display:none">';
for ($x = 0; $x++ < $times;) {
?> echo $x;
}
echo '<-br/>'.round(1000 * (microtime(true) - $start));

$start = microtime(true);
echo '<-div style="display:none">';
$sBuf = '';
for ($x = 0; $x++ < $times;) {
$sBuf .= ' '.$x;
}
echo $sBuf;
echo '<-br/>'.round(1000 * (microtime(true) - $start));

$start = microtime(true);
echo '<-div style="display:none">';
$sBuf = '';
for ($x = 0; $x++ < $times;) {
$sBuf .= ' ';
$sBuf .= $x;
}
echo $sBuf;
echo '<-br/>'.round(1000 * (microtime(true) - $start));

$start = microtime(true);
echo '<-div style="display:none">';
$GLOBALS['bufbuf'] = '';
for ($x = 0; $x++ < $times;) {
$GLOBALS['bufbuf'] .= ' '.$x;
}
echo $sBuf;
echo '<-br/>'.round(1000 * (microtime(true) - $start));

die('<-br/>bye');
}


Here is a sample output:

Looping for 10000 times - results in msec
3044
5503
10
15
16
bye


On this run using multiple echo calls + PHP escaping took 55 TIMES MORE than buffering the output in a variable. This clearly proves that the style suggested by Symfony templates, using many PHP echo blocks, is HIGHLY inefficient. If you have a few dozens of it in your templates and your content is cached, this is negligible. If your content is very dynamic, as is the case with Colnect, we're talking about something very worth noting.

Link and Search

Did you like reading it? Stay in the loop via RSS. Thanks :)