jnunemaker/mongomapper — pull request #470 by cheald (2012-10-22 01:03:53+00:00)
Title: Faster read keys

Massive improvements to Keys. `#read_keys` memoizes typecast values so that extraneous typecasts are avoided. Reworked Dirty a bit to avoid extraneous calls to `Keys#attributes`, which (by necessity) builds a new HashWithIndifferentAccess per call. Cached array builds in a few places.

The overall effect is that 1) calls to `read_keys` are dramatically reduced, 2) when `read_keys` is invoked, repeated calls to it don't repeatedly do typecasting,

This does also include my first-pass fix for the double cursor iteration, though those commits aren't necessary and the other fixes can be cherry-picked.

By means of demonstration, here's a shot of a couple of kcachegrind traces of one of my DB-heavier actions. Left is the current gem version, right is this branch. Anecdotally, my test suite runtime dropped from 57 -> 43 seconds after these changes, and my heavier DB pages are north of twice as fast.

![Trace details](http://cl.ly/image/2p0d1C0K3M35/Image%202012-10-21%20at%205.47.45%20PM.png)