On sites with a lot of translations locale() is quite slow, as for every call drupal_static is called.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Needs review
FileSize
43.36 KB
762 bytes

Here is a xhprof screenshot + a patch

dawehner’s picture

Issue tags: +Performance

Add tag

droplet’s picture

Status: Needs review » Closed (duplicate)
Issue tags: -Performance
dawehner’s picture

Status: Closed (duplicate) » Needs review
Issue tags: +Performance

The other issue is about the static in t() this one about the one in locale(), this seems to be fundamental different places

Kars-T’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
54.03 KB
37.93 KB

This patch is an exact copy of what is done in user_access()

  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['perm'] = &drupal_static(__FUNCTION__);
  }
  $perm = &$drupal_static_fast['perm'];

So as this is in core I'd say code wise it is good.

On the performance side I did test this on our biggest site and added some xhprof screenshots as well. It's over 2.500 calls to drupal_static() we can cut away with this in my environment.

Standard Drupal Core

standard_0.png

Patched Drupal Core

patch_0.png

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Looks good, thanks for the xhprof screenshots :)

Committed/pushed to 8.x.

Moving for backport just in case.

dawehner’s picture

FileSize
742 bytes

Here is a patch for 7.x

dawehner’s picture

Status: Patch (to be ported) » Needs review

Update status

Kars-T’s picture

Status: Needs review » Reviewed & tested by the community

Very same patch as in D8 except the file path. So I set this again to RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Fancy pants. :)

Committed and pushed to 7.x. Thanks!

dawehner’s picture

Awesome!

Thanks for committing the patch!

Automatically closed -- issue fixed for 2 weeks with no activity.