I looked into caching permission checks in a global variable, so it's only cached within a single thread.
It's cheap and safe, because permissions typically don't change within a single thread, so we don't have the complications with flushing the cache.
On the other hand, it doesn't help all that much. Anecdotal evidence suggests only about one to three permission checks on a typical page are redundant (read/admin on main site).
Is this something I should put in on HEAD? Or are there other permissions improvement schemes in the works?
A related question: On the subsite index page, I currently get the list of packages and subsites using the site-map, then do individual calls to permission::permission_p to check if the user has read on them.
Would it be better to rewrite this as a single query that queries the site-map and does permission_p in the where clause?
/Lars