5

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'?

Kevin Owocki
  • 1,368
  • 2
  • 11
  • 9
  • 3
    Out of curiousity, how long does it take to a) generate the rest of the page, b) download the page? – Matthew Scharley Nov 28 '09 at 23:30
  • Depending on the page and the amount of information it loads, it can take 0s to 0.5s to generate the rest of the page, and usually about 0.2s-1.1s. to download the page.. I want to squeeze as much as I can out of the page. :P – Kevin Owocki Nov 28 '09 at 23:33

1 Answers1

8

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
  • 442,112
  • 142
  • 972
  • 1,088
  • I think if we made that bet you'd probably win. :P I'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 Nov 28 '09 at 23:35
  • 2
    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 Nov 28 '09 at 23:38
  • 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 Nov 29 '09 at 00:01
  • 1
    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 Nov 29 '09 at 00:06