From: Ryan Davis Date: 2010-10-16T07:02:27+09:00 Subject: Re: Process for optimizing ruby code On Oct 15, 2010, at 06:20 , Andrew Wagner wrote: > That said, I'm wondering if there are any suggestions out there for > tutorials on using ruby-prof. Not tutorials like "here are what the numbers > mean", but "here are some suggestions for looking at the numbers and > deciding where you'll get the most gain in optimizing. The biggie for me is to look at the values in the % column and see what the curve is like: (contrived) % time call 36% w 10% x 5% y 1% z vs: % time call 5% w 4% x 3% y 1% z In the first example, you have something more akin to a power law curve. That says that a majority of the time is being spent in a minority of the calls and is a good candidate for optimizing. You then need to look and see if it is the number of calls that is causing it (which would mean it is a good candidate for memoization or some other form of caching) or if it is from accessing external resources that block or... something. It is also a good candidate to use something like zenprofile's spy_on method to figure out where the calls are coming from to determine the breakdown. If it is evenly distributed then it might not actually be worthwhile to memoize. It really depends on the design of the code and how it is used. In the second example, while the times of the profile might be high, the % of time spent is not... graphing that is pretty flat... it is relatively linear with a fairly flat slope.