rails/rails — pull request #11905 by johnskopis (2013-08-15 21:31:41+00:00)
Title: Defer stacktrace filtering in `load_missing_const`

Rails loads missing constants in `const_missing` by looping through
the most specific to the least specific constant, calling
`load_missing_const`. When the more specific constant doesn't exist
`load_missing_const` raises a NameError, with a filtered stacktrace.
The NameError is usually discarded by `const_missing`.

The stacktrace filtering, i.e. `caller`, is expensive. We can avoid
the performance penalty by deferring the stacktrace filtering until we
actually want to raise the NameError in `const_missing`.

This appears to be fixed, or at least handled differently, in rails4.

Each call to `caller` takes approximately 60ms and can happen numerous
times throughout the request response cycle.