Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295324

Statically cache Role entities to speed up (User|UserSession)::hasPermission()

$
0
0
  • Every call to hasPermission() does $roles = \Drupal::entityManager()->getStorageController('user_role')->loadMultiple($this->getRoles()); for both logged in users and anonymous users.
  • The config records themselves are statically cached within ConfigFactory, so successive loads of the same role don't require additional IO.
  • However, each load requires invoking the entity constructor, Role::postLoad(), hook_entity_load(), and hook_user_role_load().
  • The entity system includes a static cache feature (enabled via the static_cache annotation key) that allows the above to be bypassed for static cache hits.
  • Currently in HEAD, @ContentEntityType defaults static_cache to TRUE (since for content entities, there's a significant IO savings) and @ConfigEntityType defaults it to FALSE (since for config entities, it only saves on a few function calls, not on IO). There are no individual entity types in HEAD that override this default.
  • Because hasPermission() is called so frequently, this issue makes Role the first config entity type to use static_cache.
  • Xhprof screenshot from a few months ago (possibly outdated): Anon frontpage get comparison of UserSession::hasPermission().

Viewing all articles
Browse latest Browse all 295324

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>