2
0

performance-localization.xml 4.8 KB

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