News:

Looking for documentation? Take a look on our wiki

Main Menu

Products with a lot of custom values displays extremely slow

Started by sandomatyas, April 09, 2015, 16:42:40 PM

Previous topic - Next topic

sandomatyas

I have a Joomla 2.5 + VM 2 site with ~250 products. Some of them have two string type custom fields with a lot of values. I mean over 1000 or even over 2000 values. It works perfectly with VM2, the product details page generates in 2 seconds, but I want to upgrade the site to Joomla3 and VM3.
I created the fields and the product the same way but the display is extremely slow. If I have ~2000 variations, VM3 generates the product display in 80 or 90 seconds.
These are the settings of the field http://i.imgur.com/80zqiVS.png
I can do some PHP so I checked the source code and I found that the thing is with this line in the view.html.php:
$customfieldsModel -> displayProductCustomfieldFE ($product, $product->customfields);
If I check the customfields model, the slow is somewhere between line 1083-1119, in this block
{if(!empty($customfield->is_input)){
The first one is the price calculation and the other one is the JHtml generation. I don't get why do I need to generate html selects over 2000 times.

Could you help me with this thing? This is the only one thing which I need to complete my new shop.

Studio 42

In front or back-end ?
What can be slow is choosen dropdown script.
vmJsApi::chosenDropDowns();
$tmpField = clone($customfield);
$default = reset($customfields[$selectList[$customfield->virtuemart_custom_id]]->options);


Comment the line , to find what is slowing your render.


sandomatyas

It's on the frontend.
I found these lines as the slowest parts:
$price = self::_getCustomPrice($productCustom->customfield_price, $currency, $calculator);
$customfields[$selectList[$customfield->virtuemart_custom_id]]->display = JHtml::_ ($selectType, $customfields[$selectList[$customfield->virtuemart_custom_id]]->options,
$customfields[$selectList[$customfield->virtuemart_custom_id]]->customProductDataName,
$class, 'virtuemart_customfield_id', 'text', $default->customfield_value,$idTag);

If I comment this line, then the whole page generates under a second of course without the custom field:
$selectList[$customfield->virtuemart_custom_id] = $k;
It works well under VM2 but I'm stucked here :(

Studio 42

Certainly, something is set over and over in a loop for nothing.

Simply moving the code outside the loop, can solve your problems, I don't have a sample that slowdown a site as yours to test, try to look if some instance, is not set each time (or a function call), it's only such type of mistake that can slowdown your site (or an infinite loop in a plugin).

I have do some test last year for my own, you can have the same solution running 100 time slower when not optimised and this can be with only one bad line of code.
If you test my free sitemap for vm, it generate 3000 products per seconds on a standard server. My first bench was running 200 products per seconds. this was only because mysql queries loops. I don't use anymore mysql loops, but  3 php loops to get same result and it's 20X faster.

If you find the bad code, you can have chance, only one line is bad. But i cannot investigate all the code for you.