views:

75

answers:

1

I have a 1.9MB PHP library that I am including at the beginning of my scripts. It contains all of my database objects, methods, etc necessary for my website. It takes 0.1s to 0.3s to include it each time.

I use eAccelerator to cache the bytecode of this file. What else can I do to optimize the performance of this 'include'?

+6  A: 

Split it into modules and load the chunks only when needed. I think that is the only way to really improve performance, I have been in the same situation and only that solved it. It's a lot of code to include, in my mind too much. I'll bet you a beer that you do not need all 1.9MB of code in every context.

Pekka
I think if we made that bet you'd probably win. :PI've read about splitting the library up into modules. The design question now, becomes: What is the best methodology for splitting up the files?I'm also considering using php's built in __autoload methods to include classes as they are called, but this seems to have a little bit of overhead.
Kevin Owocki
To answer that, you would have to elaborate a bit on what kind of a project this is and what the library consists of. Generally, obviously, you would split them up thematically into groups of most frequently used functions/objects. Image functions here, security functions there... But that is something that lastly only you can decide.
Pekka
It's a large project with quite a few different subsets of functionality. The library consists of objects/methods and database schema maps of Images, security, friendships, Users, Groups, messages, 'pokes', etc. I'm afraid that the functionality used on each page is not well mapped, so creating a map of requests to required libraries would be my primary concern as it would be my biggest timesink.
Kevin Owocki
I would recommend doing this by hand: Creating a file (=module) structure that makes sense. This is also very healthy from a maintenance point of view. Funnily enough, I asked a related question today: http://stackoverflow.com/questions/1812472/in-a-php-project-how-do-you-organize-and-access-your-helper-objects
Pekka