There is a lot of good thinking in this memorable thread about 
acs_permission.permission_p: 
https://openacs.org/
bboard/q-and-a-fetch-msg.tcl?msg_id=0001Sm&topic_id=12&
topic=OpenACS%204%2e0%20Design.
I'd like to revive that discussion since I'm tuning permission_p 
with real data (87,000 objects, many  are 5 generations deep etc 
etc).
Right now permission_p is a series of 5 queries.  The proc 
returns when it hits its first 't' or else returns 'f' after running all 5.  
Here is a quick summary with an indication of relative cost:
- Group permission: expensive
 - Rel segment permission: expensive
 - Direct permission: cheap
 - Public permission: expensive
 - Public-like permission: cheap
 
The cheap queries are cheap for the simple reason that they 
access just acs_object_grantee_priv_map without extra joins.   
Just for fun, here are some measurements I made using 
tkyte's timestamping 
code:
    GROUP_    REL_SEG     DIRECT      PUBIC PUBLIC_LIKE
---------- ---------- ---------- ---------- -----------
.281416667 .200166667    .003875 .272708333  .002166667
These are the average number of seconds spent on each query 
over about 24 calls.
Moving on...what can we do to make things better?  One option 
is to go after the individual queries.  This may yet bear some 
fruit.  
[Aside: One thing I don't grok is the join with the users table in 
the "public" query.  When a non-registered member of the public 
makes a request, the auth system will return 0 as their user_id.  
But the users table doesn't have an entry for user_id=0, so this 
query really is checking for registered users, right?  But if that's 
the case, why is it called "public" and why is the check for 
grantee_id=-1 (the public) ?]
Another thing we can do is re-arrange the queries for maximum 
efficiency.  Since the public-like query is cheap and will very often 
return 't' (most sites have a lot of public pages), there may be a 
general benefit from putting it first.  We might as well also put the 
other cheap query---direct permissions---near the top.  After that 
the results would probably be mixed.
A third approach would be to either add extra functions or 
parametrize permission_p to give developers more control.  If for 
example, I am willing to say that a particular permission should 
never be granted to the public, can I use that information to my 
benefit by calling a different function or skipping some of the 
queries?
I wanted to put these out ideas out here because I know there 
has been a lot of good thinking and this may not be reflected in 
CVS.  I hope to generate discussion so we can recapture the 
good thinking, make some calls and get the changes in.
We have a big database of migrated content so I'm happy to do 
some trial and error and report back here.
Any takers?