<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Dan Chak's Blog &#187; hash</title>
	<atom:link href="http://blog.chak.org/tag/hash/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chak.org</link>
	<description>Tackling big problems with Ruby on Rails</description>
	<lastBuildDate>Tue, 22 Dec 2009 16:07:11 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.chak.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/16647f466ca78d98000f2fa816d200d0?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Dan Chak's Blog &#187; hash</title>
		<link>http://blog.chak.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.chak.org/osd.xml" title="Dan Chak&#8217;s Blog" />
	<atom:link rel='hub' href='http://blog.chak.org/?pushpress=hub'/>
		<item>
		<title>Speeding up ActiveRecord with Hashes, Take 2</title>
		<link>http://blog.chak.org/2008/02/09/speeding-up-activerecord-with-hashes-take-2/</link>
		<comments>http://blog.chak.org/2008/02/09/speeding-up-activerecord-with-hashes-take-2/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 15:41:22 +0000</pubDate>
		<dc:creator>Dan Chak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://thechak.wordpress.com/?p=13</guid>
		<description><![CDATA[A few weeks ago, I posted about the release of my gem, hash_extension, which makes Ruby hashes act a little more like plain old objects.  That&#8217;s a good thing, because ActiveRecord requests that return hashes instead of full-blown ActiveRecord objects are about 50% faster.  50% is not a performance tweak &#8212; it&#8217;s basically [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.chak.org&blog=1361932&post=13&subd=thechak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I <a href="http://blog.chak.org/2008/01/22/activerecord-is-slow-hashes-are-fast/">posted</a> about the release of my gem, hash_extension, which makes Ruby hashes act a little more like plain old objects.  That&#8217;s a good thing, because ActiveRecord requests that return hashes instead of full-blown ActiveRecord objects are about 50% faster.  50% is not a performance tweak &#8212; it&#8217;s basically the best thing that&#8217;s ever happened to ActiveRecord.</p>
<p>In version 0.0.1, the only way to get back hashes from ActiveRecord for use with hash_extension was to use <tt>select_all</tt>:</p>
<pre class="brush: ruby;">
Foo.connection.select_all(&quot;select * from foo&quot;)
</pre>
<p>In the docs for hash_extension I put out a call for someone to extend ActiveRecord itself to return hashes from more natural, ActiveRecord-esque methods.  Elliot Laster answered that call, and now, in version 0.0.2, <tt>find_as_hashes</tt> and <tt>find_by_sql_as_hashes</tt> are now available:</p>
<pre class="brush: ruby;">
Foo.find_as_hashes(:all)
Foo.find_as_hashes(:first)
Foo.find_as_hashes(:all, :conditions =&gt; &quot;bar = 'baz'&quot;)
Foo.find_by_sql_as_hashes(&quot;complex sql goes here&quot;)
</pre>
<p>To learn more about the gem and to download, go <a href="http://enterpriserails.rubyforge.org/hash_extension/">here</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thechak.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thechak.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thechak.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thechak.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thechak.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thechak.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thechak.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thechak.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thechak.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thechak.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thechak.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thechak.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.chak.org&blog=1361932&post=13&subd=thechak&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.chak.org/2008/02/09/speeding-up-activerecord-with-hashes-take-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee1431ee214e99538062cee9b280c479?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan Chak</media:title>
		</media:content>
	</item>
		<item>
		<title>ActiveRecord is slow.  Hashes are fast.</title>
		<link>http://blog.chak.org/2008/01/22/activerecord-is-slow-hashes-are-fast/</link>
		<comments>http://blog.chak.org/2008/01/22/activerecord-is-slow-hashes-are-fast/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 19:42:49 +0000</pubDate>
		<dc:creator>Dan Chak</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[scaling to enterprise]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.chak.org/2008/01/22/activerecord-is-slow-hashes-are-fast/</guid>
		<description><![CDATA[Introducing the hash_extension gem&#8230;
&#8230;the first gem associated with my upcoming book, Scaling to Enterprise with Ruby on Rails.
Are you tired of hearing that Ruby is slow?  Well, Ruby is slow, in many ways.  The trick to a fast site is to not use the parts of Ruby and Rails that are slow in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.chak.org&blog=1361932&post=11&subd=thechak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<h3>Introducing the <a href="http://enterpriserails.rubyforge.org/hash_extension/">hash_extension</a> gem&#8230;</h3>
<p>&#8230;the first gem associated with my upcoming book, <i>Scaling to Enterprise with Ruby on Rails</i>.</p>
<p>Are you tired of hearing that Ruby is slow?  Well, Ruby <i>is</i> slow, in many ways.  The trick to a fast site is to not use the parts of Ruby and Rails that <i>are</i> slow in places where performance counts.  For example, loading ActiveRecord objects happens to be extremely slow.  Something simple like the following statement may take very little database time, but then will spin through the slow process of ActiveRecord object creation.</p>
<pre class="brush: ruby;">
MyObject.find(:all)</pre>
<p>On my dual core macbook pro, on a table with 40k records, this takes 7 seconds of Ruby time.  Conversely, the following query, which returns not an array of ActiveRecord (MyObject) objects, but an array of hashes with all the same properties, takes just over 3 seconds:</p>
<pre class="brush: ruby;">
MyObject.connection.select_all(&quot;select * from my_objects&quot;)</pre>
<p>So if you don&#8217;t need the associations or methods that come with the full ActiveRecord version of your data, you can save a lot of Ruby cycles by using hashes instead &#8212; over 50% of the overhead.   The problem is that the two statements above are not drop-in replacements for each other.  Objects follow dot notation (<tt>f.attr</tt>) whereas hashes follow, well, hash notation (<tt>f['attr']</tt>).  So to switch to the hash result, you would have to update all your code to follow hash notation instead of dot notation, and that&#8217;s a pain (not to mention ugly).</p>
<p>hash_extension to the rescue!  This gem allows you to access hashes just as you would regular objects.   With this gem, the following is possible:</p>
<pre class="brush: ruby;">
&gt;&gt; hash = Hash.new
&gt;&gt; hash.foo = 'bar'
&gt;&gt; hash.foo
=&gt; 'bar'</pre>
<p>Now the two statements above <i>are</i> interchangeable.  If you have slow pages in need of tuning, and you&#8217;re loading lots of object for display purposes only (e.g., you don&#8217;t actually need the weight associated with the full objects), this is an easy way to eek out some more performance.You can download the gem <a href="http://rubyforge.org/projects/enterpriserails/">here</a> and read more about how to set it up and use it <a href="http://enterpriserails.rubyforge.org/hash_extension/">here</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thechak.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thechak.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thechak.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thechak.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thechak.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thechak.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thechak.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thechak.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thechak.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thechak.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thechak.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thechak.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.chak.org&blog=1361932&post=11&subd=thechak&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.chak.org/2008/01/22/activerecord-is-slow-hashes-are-fast/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee1431ee214e99538062cee9b280c479?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan Chak</media:title>
		</media:content>
	</item>
	</channel>
</rss>