[development] reducing module size
Bob Hutchinson
hutchlists at midwales.com
Wed Feb 2 18:16:56 UTC 2011
On Wednesday 02 February 2011, Bob Hutchinson wrote:
> I have a module whose functions are only used by logged-in users, it
> provides nothing to 'Anonymous' users except for a block.
> I'm considering loading most of the functions only when $user->uid > 0
> probably in hook_init()
>
> My question is, which functions would have to be loaded in order for things
> not to break, apart from the block functions (and any that it uses)?
>
> Any insights would be most welcome before I try it out.
Replying to my own mail here, I would like to thank all for the most
interesting responses.
I had already exploited the menu include method as far as I reasonably could,
so I tried moving all the functions in the main module file (except for the
hooks and their immediate dependencies) into a new file and loaded it in
hook_init using module_load_include() so that they would only load when
$user->uid > 0
This has worked just fine, both in D6 and D7 versions
I also created a new install and enabled the module, works fine. (D7 only but
I'm confident it will work in D6 too)
Doing this has reduced the module's footprint by over 100k for anonymous user
accesses, well worth while for a relatively minor file reorganisation.
Randy Fay's point about PHP caching is interesting, for a HA site on it's own
dedicated box loading all into memory is the way to go, but for your average
Hosted site this would likely not be available so this method is useful.
Thanks to all ;-)
--
-----------------
Bob Hutchinson
Midwales dot com
-----------------
More information about the development
mailing list