performance-localization.xml 5.2 KB

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