View Single Post
  #1  
Old 09-12-2006, 09:58 PM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Variant performance improvement in 4.0

More results from my profiling work. It seems when X-Cart is displaying the product page it gets pricing for each of the variants for the product. One of the things that requires is looking up the tax rates for the product. No matter which variant you are talking about the tax rate is the same but X-Cart calls a function to find out for every variant anyway. In one lower level function they they tried to cache the result to speed it up but they goofed and it only works for logged in users. This mod fixes the low level caching to work for not logged in users and adds caching at a higher level function for even more improvement. The performance improvement naturally depends on the number of variants the product has. On my test box I'm seeing roughly 1/4 second for 40 variants. On my faster production server its a little more than 1/2 that. It makes a product page with a lot of variants about as fast as one with only a couple of variants.

This is for version 4.0.x. Looks like at least 4.0.12 through 4.0.19. I guess X-Cart must have done some profiling too as they have added the higher level caching in 4.1 which is where the big gain is. I don't think 4.1 users will find any noticeable improvement if they were to implement the lower level cache fix only.

In func.php function func_get_customer_zones_avail find this:
PHP Code:
$customer_info[$address_prefix."country"] = $config["General"]["default_country"];
        
$customer_info[$address_prefix."state"] = $config["General"]["default_state"];
        
$customer_info[$address_prefix."county"] = $config["General"]["default_county"];
        
$customer_info[$address_prefix."zipcode"] = $config["General"]["default_zipcode"];
        
$customer_info[$address_prefix."city"] = $config["General"]["default_city"]; 
and add this line right after it:
PHP Code:
$customer_info["login"] = "!!!DEFAULT!!!"

Then in func.php function func_get_product_tax_rates find:
PHP Code:
$productid $product["productid"]; 

And replace it with this:
PHP Code:
static $tax_rates;
  static 
$last_productid;
  static 
$last_login;
    
    
$productid $product["productid"];
  
  if (
$productid == $last_productid && $login == $last_login)
    return 
$tax_rates;
  else {
    
$last_productid $productid;
    
$last_login $last_login;
  } 
WARNING: My tax is simple - one state, one rate. I don't display taxed prices on product pages. I am pretty confident this works but I haven't tested it outside my situation. Proceed with caution if you have complex taxation or display taxed prices on the product page.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote