LemonStand Forum: Optimization Issue - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Optimization Issue

#1 User is offline   Phil 

  • Lemonholic
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 07 September 2010 - 05:03 PM

Hey guys,

I've been looking in to speeding up Lemonstand for a client and did some profiling with XHProf. I found a very interesting bottleneck on the Category pages. 354 calls of uniqid() - which you call in the DB_ActiveRecord constructor - were responsible for a little over 13% of the total processing time.

This seemed way too high, so I did some investigation. Based on the following blog post http://portfolio.tec...ed.com/notes/44, all you need to do is change the uniqid() calls with uniqid("", true) and you'll see a very significant speed increase, especially when loading lots of ActiveRecord records. The major culprit here is on line 226 of db_activerecord.php, although it's also called in a few other places.

I can verify this is true, as after this change uniqid() was responsible for roughly 1.5% of processing time rather than 13% and I saw load times decrease by approximately .7 seconds.

I'm also experimenting with caching template output with APC - would you be interested in my code changes there also?

This post has been edited by pnomolos: 07 September 2010 - 05:22 PM

0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 07 September 2010 - 05:25 PM

Hi!

Thank you for letting us know about this issue! We will update the code.

BTW, how many products you display on the category pages?

#3 User is offline   Phil 

  • Lemonholic
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 07 September 2010 - 05:26 PM

Hi Aleksey,

At this point we display 18 per page. I'm also looking into optimizing the inflector. 71,000 calls to preg_match seems a little excessive, although I understand why there's so many :D
0

#4 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 07 September 2010 - 05:42 PM

Great. Let me know if you find something interesting. I'm going too look into the performance optimization when I finish a current task.

Thank you

#5 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 07 September 2010 - 09:56 PM

Hi!

We implemented caching in the inflector. Now it does not call preg_match (and any other functions) for words it already processed. Please update your copy and check whether it helped.

Thank you!

#6 User is offline   Phil 

  • Lemonholic
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 07 September 2010 - 10:01 PM

Quote

Hi!

We implemented caching in the inflector. Now it does not call preg_match (and any other functions) for words it already processed. Please update your copy and check whether it helped.

Thank you!


Thanks Aleksey! It looks like it's helped a bit - nothing too significant, but it has cut down the calls to preg_match by nearly 50,000 :) Load times for everything are now under 3s which is much better than when I started optimizing this morning!

Thanks again,

Phil
0

#7 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 07 September 2010 - 10:04 PM

That's weird! The Category page in my local copy the inflector generates only about 30 calls of preg_match. Hmm... How do you track the function calls? Can you find where the preg_match called these 50000 times?

Thank you!

#8 User is offline   Phil 

  • Lemonholic
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 07 September 2010 - 10:58 PM

I'm using XHProf. I will PM you the report URL so you can take a look.
0

#9 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 08 September 2010 - 12:09 AM

Thank you. I'm going to profile the script with NuSphere products. Will begin tomorrow. :-)

#10 User is offline   Phil 

  • Lemonholic
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 08 September 2010 - 09:36 AM

Aleksey,

Another potential optimization idea. Right now you're currently using eval() to bring in the template code. Have you considered saving that code to a flat file and using include() instead? That would allow PHP caching mechanisms to cache the template bytecode as well, which may result in some speed-ups.
0

#11 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 08 September 2010 - 01:28 PM

Hi!

Yes, we are going to implement a file-based templating system in the future.

BTW, have you seen my response to your private message?

Thanks!

#12 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,344
  • Joined: 31-October 09

Posted 12 September 2010 - 08:34 PM

Hi, Phil!

We made some performance improvements in the core. Please update your copy and check whether the category page loads faster now.

Thank you

#13 User is offline   Phil 

  • Lemonholic
  • PipPipPip
  • Group: Members
  • Posts: 186
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 12 September 2010 - 09:40 PM

Hi Aleksey,

Excellent, I'll take a look tomorrow :) I also sent you a PM back.

Cheers,

Phil
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users