An ActiveRecord Rewrite: the Story Behind the Attributes API
summary
A refactor rearchitects ActiveRecord type casting into an Attributes API with per-attribute objects delegating to type objects, replacing spaghetti overrides across modules. It starts as a huge PR — 37 files changed — and addresses decades of leaking behavior, closing many bugs; initial maintainability gains cause a perf hit of thousands of allocations but get reclaimed by lazily instantiating objects, dropping an example from 800 Ruby allocations reduced to 60. The work is extracted to active model and stabilizes upgrades.
AI-written summary · about
chapters (10)
- 0:00Attributes API rewrite intro
- 1:45Origins of Attributes API
- 3:33Problems with monkey patching
- 5:17Type casting before rewrite
- 7:27Type casting spaghetti code
- 8:52Refactoring to maintainable Ruby
- 11:03Performance vs maintainability
- 13:49Maintainability over speed
- 15:37Open source contribution tips
- 17:44Final thoughts
related talks
27mRediscovering ActiveRecord
38mDesigning a Great Ruby API - How We're Simplifying Rails 5
34mRefactoring Rails
39mThe Elusive Attribute
24mRails 5 Features You Haven't Heard About
34mRails 5 Features You Haven't Heard About
41mAn Intervention for ActiveRecord
37mPatters to deal with big ActiveRecord models
