performance-localization.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 XML 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><para>
  32. <emphasis>Array</emphasis>: this is the fastest, as it is,
  33. by definition, parsed into a native PHP format immediately
  34. on inclusion.
  35. </para></listitem>
  36. <listitem><para>
  37. <emphasis>CSV</emphasis>: uses <methodname>fgetcsv()</methodname> to
  38. parse a CSV file and transform it into a native PHP format.
  39. </para></listitem>
  40. <listitem><para>
  41. <emphasis>INI</emphasis>: uses
  42. <methodname>parse_ini_file()</methodname> to parse an INI file and
  43. transform it into a native PHP format. This and the CSV
  44. adapter are roughly equivalent performance-wise.
  45. </para></listitem>
  46. <listitem><para>
  47. <emphasis>Gettext</emphasis>: the Zend Framework gettext
  48. adapter does <emphasis>not</emphasis> use the gettext
  49. extension as it is not thread safe and does not allow
  50. specifying more than one locale per server. As a result, it
  51. is slower than using the gettext extension directly, but,
  52. because the gettext format is binary, it's faster to parse
  53. than XML.
  54. </para></listitem>
  55. </itemizedlist>
  56. <para>
  57. If high performance is one of your concerns, we suggest
  58. utilizing one of the above adapters.
  59. </para>
  60. </sect3>
  61. </sect2>
  62. <sect2 id="performance.localization.cache">
  63. <title>How can I make translation and localization even faster?</title>
  64. <para>
  65. Maybe, for business reasons, you're limited to an XML-based
  66. translation adapter. Or perhaps you'd like to speed things up even
  67. more. Or perhaps you want to make l10n operations faster. How can
  68. you do this?
  69. </para>
  70. <sect3 id="performance.localization.cache.usage">
  71. <title>Use translation and localization caches</title>
  72. <para>
  73. Both <classname>Zend_Translate</classname> and <classname>Zend_Locale</classname>
  74. implement caching functionality that can greatly affect
  75. performance. In the case of each, the major bottleneck is
  76. typically reading the files, not the actual lookups; using a
  77. cache eliminates the need to read the translation and/or
  78. localization files.
  79. </para>
  80. <para>
  81. You can read about caching of translation and localization
  82. strings in the following locations:
  83. </para>
  84. <itemizedlist>
  85. <listitem>
  86. <para>
  87. <link linkend="zend.translate.adapter.caching"><classname>
  88. Zend_Translate</classname> adapter caching</link>
  89. </para>
  90. </listitem>
  91. <listitem>
  92. <para>
  93. <link linkend="zend.locale.cache"><classname>Zend_Locale</classname>
  94. caching</link>
  95. </para>
  96. </listitem>
  97. </itemizedlist>
  98. </sect3>
  99. </sect2>
  100. </sect1>
  101. <!--
  102. vim:se ts=4 sw=4 et:
  103. -->