rails/rails — pull request #17120 by divineforest (2014-09-30 17:52:13+00:00)
Title: Optimize ActiveModel::Name: lazy load values

This optimization optimizes heavily used in every application method `url_for` that uses ActiveModel::Name. Now ActiveModel::Name assigns a lot of vars on initialize that are not used every time but they create huge amount of strings and regexps. With this patch it uses memoization.

Example:

```ruby
url_for post
```

creates

```ruby
[[[:T_OBJECT], [1, 0, 0, 0, 0, 0]],
[[:T_REGEXP], [5, 0, 0, 0, 0, 0]],
[[:T_DATA], [6, 0, 0, 0, 0, 0]],
[[:T_HASH], [8, 0, 0, 0, 0, 0]],
[[:T_MATCH], [13, 0, 0, 0, 0, 0]],
[[:T_ARRAY], [16, 0, 0, 0, 0, 0]],
[[:T_NODE], [19, 0, 0, 0, 0, 0]],
[[:T_STRING], [149, 0, 0, 0, 0, 0]]]
```

With this patch it creates only

```ruby
[[[:T_OBJECT], [1, 0, 0, 0, 0, 0]],
[[:T_REGEXP], [2, 0, 0, 0, 0, 0]],
[[:T_DATA], [6, 0, 0, 0, 0, 0]],
[[:T_HASH], [7, 0, 0, 0, 0, 0]],
[[:T_MATCH], [7, 0, 0, 0, 0, 0]],
[[:T_ARRAY], [13, 0, 0, 0, 0, 0]],
[[:T_NODE], [13, 0, 0, 0, 0, 0]],
[[:T_STRING], [70, 0, 0, 0, 0, 0]]]
```

So it creates `70` instead of `149` strings on every use of ```url_for``` call.