From: "Jesús Gabriel y Galán" Date: 2010-10-16T04:33:59+09:00 Subject: Re: Process for optimizing ruby code On Fri, Oct 15, 2010 at 4:54 PM, Robert Klemme wrote: > On Fri, Oct 15, 2010 at 3:20 PM, Andrew Wagner wrote: >> So, I've got a chunk of code which needs optimizing. Yes, it really needs >> it, I'm not optimizing prematurely. It (mostly) works, it's just way too >> slow. And I knew it would be too slow when I wrote it, I just wanted to come >> up with a simple implementation first, and get it under test. >> >> 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. > > That's the usual approach when tuning: take the slowest part, make it > faster.  Repeat until performance is sufficient - or you run out of > money. > > A generally candidates for optimization is object allocation.  That is > slow compared to other operations because of the GC management > involved.  Also, if you do lookups in huge Array you might want to > switch to indexed access via Hash. Also check if you have: slow DB queries, calls to external services, system calls that might be slow. Loops around any of the issues above. Jesus.