Jump to content

Google's 'PHP performance tips'


nrg_alpha

Recommended Posts

Seems Google botched some PHP tips, as a PHP team member responded on Google Groups.

 

I was aware about creating copies of variables not doubling memory due to this article. But Gwynne debunked it pretty quickly as well with the simple snippet test:

$data = str_repeat("*", 512 * 1024); // synthesize 512K of data
$memory_used_before = memory_get_usage();
$more_data = $data;
$memory_used_after = memory_get_usage();
print "Before: {$memory_used_before}\nAfter: {$memory_used_after}\n";

The part of Google's suggestion about when using strings without variables, one should use single quotes as opposed to double quotes (due to the PHP interpreter having to scan through and replace variables with their values) is how I understood it. Turns out, Gwynne was right; PHP does indeed deal with strings without variables faster in double quotes instead of single quotes (take the example found at http://pastie.org/523023 and test it without variables involved). So that one admittedly threw me off somewhat.

 

The Google article delves into more things (like switch/case vs if/else, echo vs print, etc..) But on the whole, seems Google opened mouth and is now about to insert foot.

Link to comment
Share on other sites

I just had a look at the article/videos and the response from the php team. I've always been a strong follower of many google apps, and enjoy watching their efforts to change the web to the better. It seems this time they messed up... royaly!

 

As usual I like their outlook, the idea of a colaborative effort to speed up the web, it's just unfortunate that they let someone push out suggestion with no knowledge of the working of php. I'm not a person who's looked into the inner workings of php, and it's use of different C syntax (and other lagnauges) and how similar functions compare, but I never claimed to.

 

It looks like they've asked a sheep to talk about a sheppard.

Link to comment
Share on other sites

hahaha LOL damn... it would have been one thing for average Joe programmer to step in and say that but for someone from php.net to say that.  ULTIMATE BURN.  LOL I mean, what can you say to that?  "Er...umm...shit." Open mouth, insert foot indeed!

 

I'm not going to ostracize the article poster though.  His heart is in the right place. 

Link to comment
Share on other sites

Well I noticed Eric Chiggins (the Google author in question) has responded to Gwynne (within the Google Groups link), stating that those tips were for older PHP installations (v 3 & 4). Makes me wonder out lout if this is merely to save face in public.

 

While I can see that there are hosting providers out there running older versions of PHP, I find it odd that after PHP 5 has been out for how long now, the advice wouldn't be geared towards modern PHP. Gwynne did state that those points (to some degree) were true in older versions, but is no longer the case nowadays (and add to this how PHP is configured might still not hold true even today).

 

It will be interesting to see the modifications Eric makes to his article (as he plans to amend it). I have seen the backlash on sitepoint, with comments geared towards the fact that since this is on behalf of Google, they really ought to be much more clear / concise when writing these things (due to people at large trusting what Google puts out there). So it could be largely just a matter of miss communication.. in either case, perhaps this will make Googles more cautious in the future about what exactly they put into their articles.

Link to comment
Share on other sites

Well I noticed Eric Chiggins (the Google author in question) has responded to Gwynne (within the Google Groups link), stating that those tips were for older PHP installations (v 3 & 4). Makes me wonder out lout if this is merely to save face in public.

 

That's exactly how I interpreted his response, too, LOL.  Lame attempt to save face.  Even though Gwynne did acknowledge issues for previous versions of php, he was also quick to point out that a) they MIGHT come up, depending on how you have a million diff things setup, b) even then it is not anything to shake a stick at.  So overall, lame attempt to save face.

Link to comment
Share on other sites

What the Google guy was trying to get at was entirely wrong*, but the example snippet of code he supplied was actually an example where it would double memory usage....

 

$description = strip_tags($_POST['description']);

 

$description and $_POST['description'] are no longer equal.  (Well, they could be, but they still wouldn't be to PHP as far as memory management goes.)

 

 

But, then he had to go and echo something, entirely invalidating his point.

 

 

echo strip_tags($_POST['description']);

 

Obviously the data returned from the strip_tags has to exist in memory, if just briefly.

 

 

So yeah, I guess he did straight up screw up there, but just his first part would've doubled memory (as would his second... but he didn't realize that.)

 

*I think what he was getting at was that:

$var = 'hi';
$val = $var;

 

Would double memory.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.