ZF-3457: Zend_Form_Element_Multi: _translateOption large multiOption lists


In Zend_Form_Element_Multi, the _translateOption/_translateValue take far too long to process on large lists.

Calling addElement() drastically improved when I changed nothing in the code but commenting out the if (!$this->_translateOption($option, $value)) in Zend/Form/Element/Multi.php: public function addMultiOption($option, $value = '')

As a test try making a form and calling: $form->addElement('select', 'timezone', array('label' => 'Timezone', 'value' => $timezone, 'multiOptions' => timezone_identifiers_list(), 'description' => 'Pick your timezone.'));

When I benchmarked directly around this call and nothing else using microtime() _translate made the load time about 8 seconds and with it commented the load time was about .5 seconds.


Have you set a cache for your translations ? Have you tried this several times ?

I expect that your 8 seconds come from loading the translation data in memory from disk.

I have not set a cache (do I need to?), but instead attempted to disable translations with $form->setDisableTranslator(true); (I don't intend to have any translation on the site at all) The 8 seconds was on an old dev computer I was using, my current new computer after several attempts has an average load time (for just the form load - not the whole page) of 2.52 seconds. With the two functions edited to just return* the average time is 0.38 seconds.

*The overridden functions are as follows: protected function _translateOption($option, $value) { if (!isset($this->_translated[$option])) { $this->options[$option] = $value; $this->_translated[$option] = true; return true; } return false; }

protected function _translateValue($value) { return $value; }

A patch has been applied to trunk to bail early from _translateOption() if the disableTranslator flag is true. Another user has verified that this speeds operations at the same factor as reported with commenting out the call.

Patch committed with r12201.

Changing issues in preparation for the 1.7.0 release.