performance-localization.xml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="performance.localization">
  4. <title>Internationalization (i18n) and Localization (l10n)</title>
  5. <para>
  6. Internationalizing and localizing a site are fantastic ways to expand
  7. your audience and ensure that all visitors can get to the information
  8. they need. However, it often comes with a performance penalty. Below
  9. are some strategies you can employ to reduce the overhead of i18n and
  10. l10n.
  11. </para>
  12. <sect2 id="performance.localization.translationadapter">
  13. <title>Which translation adapter should I use?</title>
  14. <para>
  15. Not all translation adapters are made equal. Some have more
  16. features than others, and some perform better than others.
  17. Additionally, you may have business requirements that force you to
  18. use a particular adapter. However, if you have a choice, which
  19. adapters are fastest?
  20. </para>
  21. <sect3 id="performance.localization.translationadapter.fastest">
  22. <title>Use non-XML translation adapters for greatest speed</title>
  23. <para>
  24. Zend Framework ships with a variety of translation adapters.
  25. Fully half of them utilize an <acronym>XML</acronym> format, incurring memory and
  26. performance overhead. Fortunately, there are several adapters
  27. that utilize other formats that can be parsed much more
  28. quickly. In order of speed, from fastest to slowest, they are:
  29. </para>
  30. <itemizedlist>
  31. <listitem>
  32. <para>
  33. <emphasis>Array</emphasis>: this is the fastest, as it is, by
  34. definition, parsed into a native <acronym>PHP</acronym> format immediately
  35. on inclusion.
  36. </para>
  37. </listitem>
  38. <listitem>
  39. <para>
  40. <emphasis><acronym>CSV</acronym></emphasis>: uses
  41. <methodname>fgetcsv()</methodname> to parse a <acronym>CSV</acronym> file
  42. and transform it into a native <acronym>PHP</acronym> format.
  43. </para>
  44. </listitem>
  45. <listitem>
  46. <para>
  47. <emphasis><acronym>INI</acronym></emphasis>: uses
  48. <methodname>parse_ini_file()</methodname> to parse an <acronym>INI</acronym>
  49. file and transform it into a native <acronym>PHP</acronym> format. This and
  50. the <acronym>CSV</acronym> adapter are roughly equivalent performance-wise.
  51. </para>
  52. </listitem>
  53. <listitem>
  54. <para>
  55. <emphasis>Gettext</emphasis>: The gettext adapter from Zend Framework
  56. does <emphasis>not</emphasis> use the gettext
  57. extension as it is not thread safe and does not allow
  58. specifying more than one locale per server. As a result, it
  59. is slower than using the gettext extension directly, but,
  60. because the gettext format is binary, it's faster to parse
  61. than <acronym>XML</acronym>.
  62. </para>
  63. </listitem>
  64. </itemizedlist>
  65. <para>
  66. If high performance is one of your concerns, we suggest
  67. utilizing one of the above adapters.
  68. </para>
  69. </sect3>
  70. </sect2>
  71. <sect2 id="performance.localization.cache">
  72. <title>How can I make translation and localization even faster?</title>
  73. <para>
  74. Maybe, for business reasons, you're limited to an <acronym>XML</acronym>-based
  75. translation adapter. Or perhaps you'd like to speed things up even
  76. more. Or perhaps you want to make l10n operations faster. How can
  77. you do this?
  78. </para>
  79. <sect3 id="performance.localization.cache.usage">
  80. <title>Use translation and localization caches</title>
  81. <para>
  82. Both <classname>Zend_Translate</classname> and <classname>Zend_Locale</classname>
  83. implement caching functionality that can greatly affect
  84. performance. In the case of each, the major bottleneck is
  85. typically reading the files, not the actual lookups; using a
  86. cache eliminates the need to read the translation and/or
  87. localization files.
  88. </para>
  89. <para>
  90. You can read about caching of translation and localization
  91. strings in the following locations:
  92. </para>
  93. <itemizedlist>
  94. <listitem>
  95. <para>
  96. <link
  97. linkend="zend.translate.adapter.caching"><classname>Zend_Translate</classname>
  98. adapter caching</link>
  99. </para>
  100. </listitem>
  101. <listitem>
  102. <para>
  103. <link linkend="zend.locale.cache"><classname>Zend_Locale</classname>
  104. caching</link>
  105. </para>
  106. </listitem>
  107. </itemizedlist>
  108. </sect3>
  109. </sect2>
  110. </sect1>
  111. <!--
  112. vim:se ts=4 sw=4 et:
  113. -->