468,554 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

do comments impose a performance hit?

I've got a PHP application that's 2 megs in size. Of that, my guess is
200k-400k is comments. Do they impose a performance hit? I've been
postponing any kind of optimization, but at some point I'll have to do
it. Is taking out the comments worth it? Of all the optimizations I can
do, where should it rank?

Jul 17 '05 #1
17 2484
On 2005-01-31, lk******@geocities.com <lk******@geocities.com> wrote:
I've got a PHP application that's 2 megs in size. Of that, my guess is
200k-400k is comments. Do they impose a performance hit? I've been
postponing any kind of optimization, but at some point I'll have to do
it. Is taking out the comments worth it? Of all the optimizations I can
do, where should it rank?

The keyword you need for your search is "profiling".
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2
On 31 Jan 2005 12:07:26 -0800, lk******@geocities.com wrote:
I've got a PHP application that's 2 megs in size. Of that, my guess is
200k-400k is comments. Do they impose a performance hit? I've been
postponing any kind of optimization, but at some point I'll have to do
it. Is taking out the comments worth it? Of all the optimizations I can
do, where should it rank?


It should rank bottom. Don't remove comments. You may get orders of magnitude
difference by fixing your algorithms, whereas removing comments may give you a
one-off small reduction in parse time, but then you don't have any comments
indicating how the code works, so it'll take longer to fix anything.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
lk******@geocities.com wrote:
I've got a PHP application that's 2 megs in size. Of that, my guess is
200k-400k is comments. Do they impose a performance hit? I've been
postponing any kind of optimization, but at some point I'll have to do
it. Is taking out the comments worth it? Of all the optimizations I can
do, where should it rank?

i would be surprised if the performance hit is more than a few tenths of a
percent at most. the amount of time spent tokenising programming languages
(which is where comments are stripped) tends to be quite small.

if, however, you are loading 2MB of scripts for every single incoming
request, i might politely suggest that you take a closer look at exactly
how the system is architected :-).

good luck!
mark.

--
I am not an ANGRY man. Remove the rage from my email to reply.
Jul 17 '05 #4
lk******@geocities.com wrote:
I've got a PHP application that's 2 megs in size. Of that, my guess is
200k-400k is comments. Do they impose a performance hit? I've been
postponing any kind of optimization, but at some point I'll have to do
it. Is taking out the comments worth it? Of all the optimizations I can
do, where should it rank?


Hi,

As said already, but I also want to stress this: Do NOT remove comments.
Comments are very important when changing things or debugging.
The performancehit is minimal.

If you want to increase performance, try Zend platform / PHP environment:
http://www.zend.com/store/products/z...orm/index.php?

It claims a much higher performance and better errorreporting for a mere
1000 bucks a year.

I have NO experience with that by the way. :P

And of course: The best way to increase performance is finding the
bottlenecks, often:
- doing repetetive queries on a database.
Solution: Redesign your queries.
- Slow algorithms.
- Opening files/scripts on another server to include in your pages.
- file IO

That kind of things.

I never ever hit any performanceproblems in my lifetime with PHP by the way,
except a few I made myself by writing stupid repetitive queries.

Tip: You can easily get a raw estimate what costs time, also called
profiling, by simple using a few timestamps in your code and write them
away to some file, or output them straight to the browser.
Possibly hidden by using <!-- routine getXXYY() took 451 ms. -->
That always worked for me.

Regards,
Erwin Moller
Jul 17 '05 #5
---------------------------------------
if, however, you are loading 2MB of scripts for every single incoming
request, i might politely suggest that you take a closer look at
exactly
how the system is architected :-).
---------------------------------------

Oh, the code doesn't come close to loading it all for each request.
It's a templating system. Not every web page is going to use every
template command. sendEmailToSiteOwner() is not going to run on the
same page as showAllCommentsForThisThread(). I think the common sense
of most web designers will keep them from loading everything on one
page. Still, I'm not sure how much actually loads ont he average page.
I've been meaning to test it. I'm guessing its in the range of 300k -
400k, depending on what template commands are being used.

Jul 17 '05 #6
Interesting that you emphasize file IO as a choke point. I thought PHP
and LInux were quick about grabbing files. Is file IO any more of a
choke point than database calls? I've been storing basic configuration
info in files because I thought grabbing it would be faster than
storing it in a MySql database.

Jul 17 '05 #7
----------------------------------
As said already, but I also want to stress this: Do NOT remove
comments.
Comments are very important when changing things or debugging.
The performancehit is minimal.
----------------------------------

It's interesting that you mention that comments are important to
debugging. I realize the truth of the statement, but I thought in other
languages, like C, it was common to write the code with comments and
then strip them out at compile time. I also thought that there were
some programs out there that could search through PHP code and pull out
all the comments for the runtime versions? I really don't know the
details, but I thought professional PHP projects would be written with
good comments and maintained that way, but actual performance code was
comment-free.

Jul 17 '05 #8
lk******@geocities.com wrote:
----------------------------------
As said already, but I also want to stress this: Do NOT remove
comments.
Comments are very important when changing things or debugging.
The performancehit is minimal.
----------------------------------

It's interesting that you mention that comments are important to
debugging. I realize the truth of the statement, but I thought in other
languages, like C, it was common to write the code with comments and
then strip them out at compile time. I also thought that there were
Not common, but rather necessary: the compiler doesn't compile comments
- they're not code! In fact, the first step when compiling C code is the
"preprocessing": removing comments, replacing constants, including files
and such.
some programs out there that could search through PHP code and pull out
all the comments for the runtime versions? I really don't know the
details, but I thought professional PHP projects would be written with
good comments and maintained that way, but actual performance code was
comment-free.


If performance is degraded by comments, a possible approach would be to
keep two source trees: one for development, with comments, and a
production copy of it where the comments have been automatically removed.
Jul 17 '05 #9

Dani CS wrote:
lk******@geocities.com wrote:
----------------------------------
<snip>
some programs out there that could search through PHP code and pull
out all the comments for the runtime versions? I really don't know the
details, but I thought professional PHP projects would be written with good comments and maintained that way, but actual performance code was comment-free.


If performance is degraded by comments, a possible approach would be

to keep two source trees: one for development, with comments, and a
production copy of it where the comments have been automatically

removed.

The php binary does just this.
php -w will remove comments and whitespace.
hth

Jul 17 '05 #10
"lkrubner" wrote:
I've got a PHP application that's 2 megs in size. Of that, my
guess is
200k-400k is comments. Do they impose a performance hit? I've
been
postponing any kind of optimization, but at some point I'll
have to do
it. Is taking out the comments worth it? Of all the
optimizations I can
do, where should it rank?


Leave the comments in, and if it becomes a performance drag (it should
not), when you deploy, then use some kind of php encrypter/obfuscator
which would remove the comments.

You are better off going with a host that has code caching (e.g.
mmcache) since in final code, comments are already stripped.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-comments...ict193238.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=657384
Jul 17 '05 #11
lk******@geocities.com wrote:
Interesting that you emphasize file IO as a choke point. I thought PHP
and LInux were quick about grabbing files. Is file IO any more of a
choke point than database calls? I've been storing basic configuration
info in files because I thought grabbing it would be faster than
storing it in a MySql database.


Hi,

Yes, I think that is right, but it is not my expertise. :-)
I didn't actually test file-IO speeds on different setups.
I all depends of course: OS, filesystem, etc.

My point being merely that you can test this by simple profiling. :-)

Regards,
Erwin Moller
Jul 17 '05 #12
So, can we conclude to leave the comments in?

Regards,
Erwin Moller
Jul 17 '05 #13
<humour>
Never waste time putting comments in code, it should be obvious what the
code does.
Always use the shortest possible names for variables and functions. Codes
are betters than proper words.
Always use lowercase names as they take up less space than uppercase names.
</humour>

--
Tony Marston

http://www.tonymarston.net

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
So, can we conclude to leave the comments in?

Regards,
Erwin Moller

Jul 17 '05 #14
Tony Marston wrote:
<humour>
Never waste time putting comments in code, it should be obvious what the
code does.
Always use the shortest possible names for variables and functions. Codes
are betters than proper words.
Always use lowercase names as they take up less space than uppercase
names. </humour>


;-)
Jul 17 '05 #15
You don't make it clear if you are doing this already, but I would
definitely recommend that you split these different commands into
separate files which would then be conditionally included into the main
application.

If you have 10,000 lines of code all in one file, but split into
several dozen functions, the compile step will optimize out all the
unused functions reducing the size of the resulting executable.
However, the parser will still have to parse all that code to determine
which functions to optimize out.

Unless you have something like mmcache, which caches the script in its
compiled state, then the parsing will have to occur on every page load.
So for the same reason you are concerned about comments ( the parser
needs to strip them all out ) you should also be concerned about having
all your code in a single file.

You will have to figure out for yourself how important it is to eke out
every last drop of performance, of course. I experimented with
including several hundred kb of PEAR scripts (but not executing any of
them) and saw a noticable increase in processing time, but even still
it was on the order of 0.017s increasing to 0.049s. Overall it is
still taking the parser less than 5/100ths of a second. But if you are
expecting this script to be used on a high-traffic site with 25-50
pageloads per second, then you will see a noticable performance hit for
parsing code (and comments?) which will not be executed.

Jul 17 '05 #16
On 4 Feb 2005 13:16:14 -0800, "Ramius" <m.******@gmail.com> wrote:
Unless you have something like mmcache


What's the modern (free) equivalent of mmcache nowadays? mmcache seems to have
died; no updates since 2003/11, they only claim tested up to PHP 4.3.4 - last
time I looked on Google I couldn't spot a free alternative. One that works on
PHP5 would be best - I'd like to move to PHP5 at work (mainly for the improved
OO support), although the instability of the Oracle support under PHP5 is still
a blocker.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #17
> What's the modern (free) equivalent of mmcache nowadays?

I'm not sure if there is one. I only mentioned mmcache because I saw
it mentioned elsewhere in this thread. A google search (
http://www.google.com/search?q=relat...r%2Eco%2Euk%2F
) turns up IonCube PHP Accelerator, mmCache, APC, and bwcache. None of
them seem to work with PHP 5, and the most recently updated, APC, seems
about 8 months old.

Jul 17 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Guotao Luan | last post: by
12 posts views Thread by Nobody | last post: by
7 posts views Thread by Naren | last post: by
5 posts views Thread by Michael Turner | last post: by
100 posts views Thread by jacob navia | last post: by
21 posts views Thread by Galen Somerville | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.