{"id":95,"date":"2008-11-06T10:58:30","date_gmt":"2008-11-06T15:58:30","guid":{"rendered":"http:\/\/www.timrosenblatt.com\/blog\/2008\/11\/06\/greggs-speeding-up-ruby-without-the-rails-presentation\/"},"modified":"2008-11-06T10:58:30","modified_gmt":"2008-11-06T15:58:30","slug":"greggs-speeding-up-ruby-without-the-rails-presentation","status":"publish","type":"post","link":"http:\/\/www.timrosenblatt.com\/blog\/2008\/11\/06\/greggs-speeding-up-ruby-without-the-rails-presentation\/","title":{"rendered":"Gregg&#8217;s &#8220;Speeding up Ruby, without the Rails&#8221; Presentation"},"content":{"rendered":"<p><font size=\"3\"><strong>Gregg&#8217;s &#8220;Speeding up Ruby, without the Rails&#8221; Presentation<\/strong><\/font><\/p>\n<p><font size=\"3\">He points out that the C library stuff is going to cause blocking, because Ruby&#8217;s threading manager doesn&#8217;t know when it can stop execution. He demos this with mysqlplus, showing 10 queries with the blocking driver, and then showing mysqlplus which is the non-blocking driver. 10x speedup.<\/font><\/p>\n<p><font size=\"3\">He points out dbslayer, which sits between processes and MySQL, and passes JSON out to the processes.<\/font><\/p>\n<p><font size=\"3\">Starling (which uses memcached) is a good tool for job queueing. Looks like it sits on a single server, and serves up jobs when requested. He demoed putting integers into the job stack, could we put whole objects into the stack?<\/font><\/p>\n<p><font size=\"3\">&#8220;What if I can&#8217;t find a C library to do what I want?&#8221; &#8212; use Ruby Inline. It lets you embed C code *directly* into Ruby.<\/font><\/p>\n<p><font size=\"3\">Also, he is talking about ruby-prof, which is for profiling Ruby code.<br \/>\n<span>    <\/span><\/font><\/p>\n<blockquote><p><font size=\"3\">gem <span><\/span>install ruby-prof<\/font><\/p><\/blockquote>\n<p><font size=\"3\"> Very nice stuff, but interpreting the output definitely requires some knowledge. One neat trick is that if you<br \/>\n<span>    <\/span><\/font><\/p>\n<blockquote><p><font size=\"3\">require &#8216;ruby-prof&#8217;<\/font><\/p><\/blockquote>\n<p><font size=\"3\"> You can start and stop the profiling so that you only get data from the parts of the code you&#8217;re interested in. Also, with this technique, you can easily output HTML formatted and linked code.<\/font><\/p>\n<p><font size=\"3\">Interesting optimizing trick<br \/>\n<span>    <\/span><\/font><\/p>\n<blockquote><p><font size=\"3\">&#8220;#{@var1} #{@var2}&#8221;<\/font><\/p><\/blockquote>\n<p><font size=\"3\"> is faster than<br \/>\n<span>    <\/span><\/font><\/p>\n<blockquote><p><font size=\"3\">@var + &#8221; &#8221; + @var2<\/font><\/p><\/blockquote>\n<p><font size=\"3\"> because method calls are expensive, and the plus signs are method calls.<\/font><\/p>\n<p><font size=\"3\">Another pro-tip: if you&#8217;re doing a switch-case, put the most common option at the top of the list &#8212; it cuts down on the number of compares that it will take to find the desired option.<\/font><\/p>\n<p><font size=\"3\">In Rails 2.2, there&#8217;s a new function called &#8220;memoize&#8221;, which will automatically handle memoizing, so you don&#8217;t have to do a<br \/>\n<span>    <\/span><\/font><\/p>\n<blockquote><p><font size=\"3\">@result ||= <\/font><\/p><\/blockquote>\n<p><font size=\"3\">Don't use .nil? calls, because method calls are slow.<br \/>\n<\/font><\/p>\n<blockquote><p><font size=\"3\"> <span>    <\/span>if !value<\/font><\/p><\/blockquote>\n<p><font size=\"3\"> or better<br \/>\n<span>    <\/span><\/font><\/p>\n<blockquote><p><font size=\"3\">unless value<\/font><\/p><\/blockquote>\n<p><font size=\"3\"> are better choices.<\/font><\/p>\n<blockquote><p><span><font size=\"3\">    <\/font><\/span><font size=\"3\">a, b = b, a # Nice trick for swapping two values<\/font><\/p><\/blockquote>\n<p><font size=\"3\">Link love for Gregg: <a href=\"http:\/\/www.envycasts.com\/\" title=\"http:\/\/www.envycasts.com\" id=\"b4mu\">http:\/\/www.envycasts.com<\/a> His presentation style is excellent, and I guarantee you will learn at least one thing you didn't know before.<\/font><\/p>\n<p><font size=\"3\"><a href=\"http:\/\/www.railsenvy.com\/rubyconf\/\" title=\"http:\/\/www.railsenvy.com\/rubyconf\/\" id=\"dew0\">http:\/\/www.railsenvy.com\/rubyconf\/<\/a> This link has more info from his presentation, and source material<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gregg&#8217;s &#8220;Speeding up Ruby, without the Rails&#8221; Presentation He points out that the C library stuff is going to cause blocking, because Ruby&#8217;s threading manager doesn&#8217;t know when it can stop execution. He demos this with mysqlplus, showing 10 queries with the blocking driver, and then showing mysqlplus which is the non-blocking driver. 10x speedup. &hellip; <a href=\"http:\/\/www.timrosenblatt.com\/blog\/2008\/11\/06\/greggs-speeding-up-ruby-without-the-rails-presentation\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Gregg&#8217;s &#8220;Speeding up Ruby, without the Rails&#8221; Presentation&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145,88],"tags":[308,310,309,208],"_links":{"self":[{"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/posts\/95"}],"collection":[{"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":0,"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.timrosenblatt.com\/blog\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}