Do unused functions slow things down?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi all,

I'm a C++ semi-veteran, and I'm fairly new to PHP.  I recently
realized it was possible to include .php files in .php scripts, and I
had a question:

Is there any harm in including a file that contains a lot of functions
that aren't used?  I know that in C++ this could make the program
larger (maybe slower also?  not sure), but obviously since PHP is a
scripting language, this shouldn't be an issue since there's no
compilation.  But, does including a file with a lot of functions that
aren't used slow down the process of genearting the output from the
script?  If yes, does it slow it down significantly?

Thanks for any insight anyone can provide.


Re: Do unused functions slow things down?

cplxphil wrote:
Quoted text here. Click to load it

Actually, a good C++ compiler/linker will optimize out unused functions,
so they have no effect at all.  As for PHP, there will be a slight
slowdown as the extra code needs to be parsed, and will take up extra

But I generally don't like to have a lot of unused functions in my code
only because it's more I have to wade through when debugging.  I try to
split functions up into related groups (actually, I use more classes
than anything else - one file per class).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Do unused functions slow things down?

Quoted text here. Click to load it

There's a slight overhead in processing time (but rather a large
memory overhead) in loading the files and parsing them (which will be
done regardless if the code is called or not.

If you're concerned then maybe you should try running some benchmarks
- either you have one large lib with all your code in and load that,
or lots of little libs and selectively load the files you want - it
may be that the performance hit is in the latency of opening the file,
in which case the selective loading technique may actually make the
system performer worse. (I keep meaning to try this out for myself,
but never found the time - if you do try it, I'm sure lots of people
here would be interested in seeing your results).

If you're writing OO PHP, then do read up on the auto loader.



Re: Do unused functions slow things down?


Quoted text here. Click to load it

There _is_ compilation in PHP. The source code is parsed, compiled into
a bytecode (intermediate code), which is then interpreted.

Quoted text here. Click to load it

Without a bytecode cache like APC for example all the code is reloaded
and recompiled on every request. This will definitely cause more work on
the server, but usually you won't notice it.

Quoted text here. Click to load it

Most performance issues are caused by the actual code, the algorithms,
not the amount of included files. To find the real bottlenecks, use a
profiler like Xdebug.


Site Timeline