Shopify/liquid — pull request #492 by pushrax (2014-12-04 21:29:06+00:00)
Title: Resource counting perf

In Shopify, profiles are showing that resource_limits_reached?/increment_used_resources are taking a disproportionately large amount of time (larger than the synthetic profiles here). To optimize them, this PR uses a class with ivars for each limit rather than a hash.

old synthetic profile:

```
==================================
Mode: cpu(1000)
Samples: 2459 (0.00% miss rate)
GC: 562 (22.85%)
==================================
TOTAL (pct) SAMPLES (pct) FRAME
...
30 (1.2%) 30 (1.2%) Liquid::Context#resource_limits_reached?
...
24 (1.0%) 24 (1.0%) Liquid::Context#increment_used_resources
...
```

new:
```
==================================
Mode: cpu(1000)
Samples: 2632 (0.00% miss rate)
GC: 561 (21.31%)
==================================
TOTAL (pct) SAMPLES (pct) FRAME
...
24 (0.9%) 24 (0.9%) Liquid::ResourceLimits#increment_for
...
15 (0.6%) 15 (0.6%) Liquid::ResourceLimits#reached?
...
```

So, `increment_used_resources` is a little faster (because of instance_of vs kind_of), and `resource_limits_reached?` is much faster.