This is an alternative to #296693: Hide empty admin categories which just adds a simple per-user cache cache to the toolbar. It looks like no-one is very keen on reverting system_admin_menu_block_access(), so this means that any module displaying administrative links has to implement their own per-user caching to avoid critical performance issues. admin_menu.module already does this with client-side caching in supported browsers. menu.module should probably use the block cache somehow - maybe we can fix that when #495968: Introduce drupal_render() cache pattern. Start using it for blocks is in, since the toolbar is meant to be used for a finite number of users, a per-user cache is the best option here.
I'm using the block_cache table because this is conveniently cleared on events like saving the permissions pages and menu_link_save().
Hoping for a quick commit here, because both the query logging and profiler noise from this makes it very difficult to evaluate other performance issues in HEAD.
Front page, no content, user 1.
Executed 43 queries in 26.31 milliseconds. Page execution time was 93.31 ms.
Executed 43 queries in 29.88 milliseconds. Page execution time was 97.41 ms.
Executed 43 queries in 24.89 milliseconds. Page execution time was 84.37 ms.
Executed 30 queries in 16.55 milliseconds. Page execution time was 71.57 ms.
Executed 30 queries in 16.96 milliseconds. Page execution time was 77.55 ms.
Executed 30 queries in 18.57 milliseconds. Page execution time was 75.16 ms.