Zend Framework

Zend_Form_Element_Multi: _translateOption large multiOption lists

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.2
  • Fix Version/s: 1.7.0
  • Component/s: Zend_Form
  • Labels:
    None

Description

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.

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Duck Williamson added a comment -

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;
}

Show
Duck Williamson added a comment - 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; }
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Matthew Weier O'Phinney added a comment -

Patch committed with r12201.

Show
Matthew Weier O'Phinney added a comment - Patch committed with r12201.
Hide
Wil Sinclair added a comment -

Changing issues in preparation for the 1.7.0 release.

Show
Wil Sinclair added a comment - Changing issues in preparation for the 1.7.0 release.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: