Re: include selectively or globally?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 28, 2012 at 3:49 AM, Adam Richardson <simpleshot@xxxxxxxxx> wrote:
> On Mon, Aug 27, 2012 at 6:54 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote:
>> On Mon, Aug 27, 2012 at 10:56 PM, Haluk Karamete
>> <halukkaramete@xxxxxxxxx> wrote:
>>>
>>> Now, the question is... should you use a global include that points to
>>> this library - across the board - so that ALL the pages ( including
>>> the 90% that do not need the library ) will get it, or should you
>>> selectively add that include reference only on the pages you need?
>>>
>>
>> Since searching for files is one of the most expensive (in time)
>> operations, you're probably best off with only a single PHP file.
>
> Maybe I misinterpreted the question, but I don't think I agree.
>
> If you have a 50K PHP file that's only needed in only 10% of the
> pages, then, when solely considering performance, that file should
> only be included on the 10% of the pages that actually use the file.
> Now, there are reasons where you might want to include the file
> globally (maintenance purposes, etc.) Loading the 50K of PHP code
> requires building up all of the associated infrastructure (zvals,
> etc.) for the user code (even if APC is used, the cached opcode/PHP
> bytecode still has to be parsed and built up for the user-defined
> classes and functions per request, even if they're unused), is
> certainly going to perform more slowly than selectively including the
> library on only the pages that need the library.
>
> Adam
>

First of all, I believe PHP is smart enough to not generate bytecode
for functions that are not used in the current file. Think about the
fact that you can write a function with errors, which will run fine
until you call the function. (except for syntax errors).

The speed difference between loading 5K file or 50K file (assuming
continuous blocks) is extremely small. If you split this library, you
would have PHP files that require you to load maybe 3 or 4 different
files to have all their functions. This would require 3 or 4 more file
searches, first the file needs to be located in the file table, then
on the disk. If you compare the required time for those operations,
they are enormous compared to time needed for a bigger file.
Just for the facts, if you're on a high end server drive (15000RPM
with 120MB/s throughput), you would have an average access time of
7ms. (rotational and seek time). Loading 5k with 120MB/s thereafter
only takes 0.04ms. 50k would take 0.4ms. That would save you 0.36ms if
a file only needs 1 include, if you need 2, that would cost you 6.68
ms. 3 would cost 13.72 ms, etc. With an 3.8GHz CPU, there are approx
4.000.000 clock cycles in 1ms, so in this case you would lose for only
loading 2 files instead of one, approx 27.250.000 clock cycles.. Think
about what PHP could do with all those clock cycles..

- Matijn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux