<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Performance on Bhaak&#39;s Blog</title>
    <link>https://bhaak.net/blog/tags/performance/</link>
    <description>Recent content in Performance on Bhaak&#39;s Blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 14 May 2026 15:23:13 +0200</lastBuildDate>
    <atom:link href="https://bhaak.net/blog/tags/performance/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Accessing ActiveRecord attribute slower than local variable</title>
      <link>https://bhaak.net/blog/posts/2026-05-14-accessing-activerecord-attribute-slower-than-local-variable/</link>
      <pubDate>Thu, 14 May 2026 15:23:13 +0200</pubDate>
      <guid>https://bhaak.net/blog/posts/2026-05-14-accessing-activerecord-attribute-slower-than-local-variable/</guid>
      <description>&lt;p&gt;I was deep in a performance optimization flow when I stumbled upon this part in&#xA;&lt;a href=&#34;https://github.com/ruby-prof/ruby-prof&#34;&gt;a ruby-prof graph&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;- 17.59% (73.45%) SomeTable::GeneratedAttributeMethods#some_attribute [30263106 calls, 44665545 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  - 15.24% (86.62%) ActiveRecord::AttributeMethods::Read#_read_attribute [30263106 calls, 49437307 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - 11.82% (77.58%) ActiveModel::AttributeSet#fetch_value [30263106 calls, 49068748 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      - 5.44% (46.06%) ActiveModel::AttributeSet#[] [30263106 calls, 49303667 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        - 2.32% (42.58%) Hash#[] [30263106 calls, 72892138 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      - 2.05% (17.36%) ActiveModel::Attribute#value [30263106 calls, 49274896 total]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;ActiveRecord stores attributes internally in a hash, which is more expensive than I expected.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
