[development] Splitting hook_menu into hook_menu and hook_router

Earl Miles merlin at logrus.com
Thu Jan 18 20:23:14 UTC 2007

Dries Buytaert wrote:
>> 2) Improved memory usage.
>> People might not care about memory and performance on the surface, but
>> ISPs care about server resource usage, site maintainers worry about  the
>> number of visitors their site can support and their hardware needs in
>> relation to supporting their community, and site visitor care about  how
>> quickly the page loads.
> Why would splitting the router and the menu reduce memory usage?   Have 
> you tested this?  I'd think you end up with more arrays and some  
> duplication.

It is true that you will duplicate the 'path' string for every item where you 
have a visible menu.

However, for every item where you don't have a visible menu, you'll eliminate 
all fields except for path, callback, callback arguments and access, and title.

However x2, you won't load non-visible menu items that aren't being used *at 
all*; they will remain safely tucked away in the database, not eating memory 
except when used. Only the *visible* portion of the menu tree would be loaded. 
This, some saved memory.

Some other good reasons:

By disconnecting the visible menu from the router...

1) ...the menu title and the page title no longer need to be the same.

2) ...we will no longer have that very frustrating bug where adding a protected 
menu entry to the visible menu would remove all access controls to the item.

3) ...we make it easier to have multiple menu items go to the same place. 
Karoly has mentioned this several times, but I believe it is important to 
re-iterate, because it matters a great deal.

4) ...we make it easier to control where in the hierarchy your menu item 
actually falls. Right now that's all very automatic based upon the path. Which 
is all fine, but sometimes that's not what the developer wants, but the 
developer has no control over it.

5) ...we'll reduce the complexity of coding for tabs. Coding for tabs doesn't 
make a lot of sense right now, we're fairly limited in what we can do with them 
vs what users expect of them. Oh and creating a menu item that points to a tab 
will destroy the tab nature of the item. Kids love that trick.

More information about the development mailing list