dkubb/ice_nine — pull request #8 by misfo (2013-09-17 21:52:43+00:00)
Title: Speed up recursion guard

A [simple benchmarking script](https://gist.github.com/misfo/6600943) shows `IceNine.deep_freeze` running ~30x faster on nested Hashes/Arrays.

We ran into some performance issues at work with using `IceNine.deep_freeze` and `include Adamantium`, so we had to switch to using shallow `.freeze`s and `include Adamantium::Flat`. I did some profiling on `deep_freeze` and it looked like the recursion guard code was taking up most of the time. In particular the [call to `Kernal#caller`](https://github.com/dkubb/ice_nine/blob/11e80fd94e5961467a8c2f3ce482ef67a2c91e36/lib/ice_nine/support/recursion_guard.rb#L21) was taking up a big percentage of the running time. `RecursionGuard.guarded_objects` was taking a smaller, but significant, percentage as well.

This commit explicitly passes the recursion guarding down the call stack. The code is, admittedly, not as clean as it was before, but it makes for acceptable performance of deep freezes on large data structures (in our case, the large data structures were deserialized responses from a JSON API).

The commit does add an additional `recursion_guard` argument to a few public methods. If you don't want those optional arguments as part of the public API, I could probably refactor those out somehow...