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? 17 2583
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>
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 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. 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
---------------------------------------
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.
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.
----------------------------------
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. 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.
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
"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 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
So, can we conclude to leave the comments in?
Regards,
Erwin Moller
<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
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>
;-)
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.
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
> 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. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by Alex |
last post: by
|
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
| | | | | | | | | | |