Cheaper request authentication
Cheaper request authentication

Parsing the auth handlers on every request is more expensive then
it needs to be. Just the regexp split operation by itself is rather
expensive:

2> Conf = couch_config:get("httpd", "authentication_handlers").
"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"
3>
3> timer:tc(re, split, [Conf, "(?<=})\\s*,\\s*(?={)", [{return, list}]]).
{289,
 ["{couch_httpd_oauth, oauth_authentication_handler}",
  "{couch_httpd_auth, cookie_authentication_handler}",
  "{couch_httpd_auth, default_authentication_handler}"]}
4> timer:tc(re, split, [Conf, "(?<=})\\s*,\\s*(?={)", [{return, list}]]).
{292,
 ["{couch_httpd_oauth, oauth_authentication_handler}",
  "{couch_httpd_auth, cookie_authentication_handler}",
  "{couch_httpd_auth, default_authentication_handler}"]}
5> timer:tc(re, split, [Conf, "(?<=})\\s*,\\s*(?={)", [{return, list}]]).
{297,
 ["{couch_httpd_oauth, oauth_authentication_handler}",
  "{couch_httpd_auth, cookie_authentication_handler}",
  "{couch_httpd_auth, default_authentication_handler}"]}
6> timer:tc(re, split, [Conf, "(?<=})\\s*,\\s*(?={)", [{return, list}]]).

And so is the parsing of each auth handler function:

1> timer:tc(couch_httpd, make_arity_1_fun, ["{couch_httpd_auth, default_authentication_handler}"]).
{63,#Fun<couch_httpd.6.41794127>}
2> timer:tc(couch_httpd, make_arity_1_fun, ["{couch_httpd_auth, default_authentication_handler}"]).
{58,#Fun<couch_httpd.6.41794127>}
3> timer:tc(couch_httpd, make_arity_1_fun, ["{couch_httpd_auth, default_authentication_handler}"]).
{56,#Fun<couch_httpd.6.41794127>}
4> timer:tc(couch_httpd, make_arity_1_fun, ["{couch_httpd_auth, default_authentication_handler}"]).
{58,#Fun<couch_httpd.6.41794127>}
5> timer:tc(couch_httpd, make_arity_1_fun, ["{couch_httpd_auth, default_authentication_handler}"]).
{59,#Fun<couch_httpd.6.41794127>}

Getting the preprocessed auth handler functions from the application
environment is however much cheaper:

6> timer:tc(application, get_env, [couch, auth_handlers]).
{13,
 {ok,[{#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_oauth, oauth_authentication_handler}">>},
      {#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_auth, cookie_authentication_handler}">>},
      {#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_auth, default_authentication_handler}">>}]}}
7> timer:tc(application, get_env, [couch, auth_handlers]).
{14,
 {ok,[{#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_oauth, oauth_authentication_handler}">>},
      {#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_auth, cookie_authentication_handler}">>},
      {#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_auth, default_authentication_handler}">>}]}}
8> timer:tc(application, get_env, [couch, auth_handlers]).
{13,
 {ok,[{#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_oauth, oauth_authentication_handler}">>},
      {#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_auth, cookie_authentication_handler}">>},
      {#Fun<couch_httpd.6.41794127>,
       <<"{couch_httpd_auth, default_authentication_handler}">>}]}}

The application environment is backed by an ets and created when
the couch OTP application is started.



git-svn-id: c1f8a8ec0b3bb2e99ab3413722f81f687760e79c@1144848 13f79535-47bb-0310-9956-ffa450edef68

fkaempfer/couchdb,fkaempfer/couchdb,fkaempfer/couchdb,fkaempfer/couchdb,fkaempfer/couchdb,fkaempfer/couchdb