[Ruby 1.9-Feature#3917][Open] [proposal] called_from() which is much faster than caller()

Feature #3917: [proposal] called_from() which is much faster than

$B5/I<<T(B: makoto kuwata
$B%9%F!<%?%9(B: Open, $BM%@john(B: Normal
$B%+%F%4%j(B: core, Target version: 1.9.x

I propose to introduce Kernel#called_from() which is similar to caller()
but much faster than it.


There are some cases to want to know from where current method is
In this case, Kernel#caller() is used.

But Kernel#caller() has performance issues for these cases.

  • caller() retrieves entire stack frame. It is too heavy.
  • caller() returns an array of “filename:linenum in `method’” string.
    User must parse it and retrieve filename and linenum by rexp.
    It is also very heavy weight task.

Therefore I propose Kernel#called_from() which is very light weight
compared to caller(). A certain benchmark shows that called_from()
is more than 20 times faster tan caller().