PHP autoloading verses utility functions in a single class file

31 Views Asked by At

I have a a class file with a lot of utility functions written as static methods. There are about 85 such functions. This file is included with every script, even though typically only a few of the functions are used for each script.

This is similar to the situation posed in the question at Autoloading utility functions.

The combined file is 168k in size and has just under 5000 lines. Opcache is enabled.

My question is the trade off between a single file load that needlessly increases the footprint of each script but only has one file to load, verses autoloading the separate class files, which would only load the ones that are needed. The tradeoff is the memory footprint of the single large file verses the much smaller footprint, but multiple loading.

I realize that the size of the functions and the relative number of them used bears on the situation; and that benchmarking is one way to make this decision. Yet I am wondering about any general guidelines that may be applicable.

EDIT

The 85 functions are for the most part relatively commonly used functions on many pages. The alternative design choices are the following:

  1. Have a single file with all the functions in one.
  2. Break them into one per file (in some cases very closely related functions would be grouped together so would not strictly be a "one-per-file"). a. Go through the trouble of deciding which of them need to be included for each script. b. Part "a" is just theoretical--would actually at that point use autoloading.

Again, the question is the trade-offs between "all-in-one" with a single file to load and large footprint, verses smaller footprint but multiple loads. I would expect that as a rule there would be 6 - 10 having to be loaded for each script. So not too excessive.

0

There are 0 best solutions below