The first Living on the Edge covered some of the API changes since Rails 2.1, and this time round, I’m going to cover the performance improvements as promised.
Jumping right in…
Faster Erb templates
The “special” Erb
_erbout has been replaced with an instance variable, which allows for:
- better (memory) performance because bindings are no longer being passed around,
- fewer eval
s which are usually expensive,
- there’s no need to slice the
_erboutvariable when you can swap in a new (string) buffer, and
- the buffer is actually available via a
output_bufferreader and writer methods (so you can override it if you want).
RecordIdentifier methods speedup
The RecordIdentifier has been sped up by some simple use of memo-ization, thus reducing the number of inflections performed, among other things. The RecordIdentifier is used widely in cache keys, partial template paths, and in most places where you identify an ActiveRecord model without caring about its actual
Lazy load cache and session stores
Update: Oops my bad, this change was later reverted in 6573f6a.
The various cache stores in the ActiveSupport::Cache module are now lazy loaded – this means that they are only
required when you actually start using them.