Kernel.caller Performance Across Different Ruby Versions

I wrote a quick Ruby script to benchmark Kernel.caller using ruby-prof.
I then ran that script manually across 3 Ruby versions.

The results indicate that Kernel.caller is incrementally slower in newer
Ruby versions.

This seems counter-intuitive to me so what am I missing? Is there
something wrong in the way I'm benchmarking Kernel.caller or the test
script itself?

The test script with ruby-prof output is available here:

A couple notes:

* For each Ruby version, I ran the test suite 5 times and pasted the
fastest output in the gist (based on total time)
* Ruby versions were standard "out of the box" as installed by rbenv
* The three Ruby versions were: 1.8.7-p374, 1.9.3-p448, 2.0.0-p247

Test Summary:

Kernel.caller Total Times across Ruby Versions
(Each test makes 500 Kernel.caller calls with 1508 frames)

Ruby 1.8.7-p374: 0.369ms
Ruby 1.9.3p448 : 0.462ms
Ruby 2.0.0-p247: 0.769ms

Any input/guidance would be appreciated. Thanks!
Peter Giacomo Lombardo

···

--
Posted via http://www.ruby-forum.com/.

Optimizing data structures (to compact byte code) to speed up common
operations, but makes uncommonly-accessed information (file names, line
numbers) more expensive to access.

I think it's a fair trade to make, caller should not be a
frequently-called method.

Btw, same idea applies to database design, creating indexes will speed
up some operations at the expense of others.

···

Peter Giacomo Lombardo <lists@ruby-forum.com> wrote:

I wrote a quick Ruby script to benchmark Kernel.caller using ruby-prof.
I then ran that script manually across 3 Ruby versions.

The results indicate that Kernel.caller is incrementally slower in newer
Ruby versions.

This seems counter-intuitive to me so what am I missing? Is there
something wrong in the way I'm benchmarking Kernel.caller or the test
script itself?

Kernel.caller is very expensive on JRuby too, much more so than MRI.

I'm curious why you're benchmarking it in the first place. `caller' is not
something you want to be calling very often

···

On Tue, Jul 16, 2013 at 10:40 AM, Peter Giacomo Lombardo < lists@ruby-forum.com> wrote:

I wrote a quick Ruby script to benchmark Kernel.caller using ruby-prof.
I then ran that script manually across 3 Ruby versions.

The results indicate that Kernel.caller is incrementally slower in newer
Ruby versions.

This seems counter-intuitive to me so what am I missing? Is there
something wrong in the way I'm benchmarking Kernel.caller or the test
script itself?

The test script with ruby-prof output is available here:
https://gist.github.com/pglombardo/5978849

A couple notes:

* For each Ruby version, I ran the test suite 5 times and pasted the
fastest output in the gist (based on total time)
* Ruby versions were standard "out of the box" as installed by rbenv
* The three Ruby versions were: 1.8.7-p374, 1.9.3-p448, 2.0.0-p247

Test Summary:

Kernel.caller Total Times across Ruby Versions
(Each test makes 500 Kernel.caller calls with 1508 frames)

Ruby 1.8.7-p374: 0.369ms
Ruby 1.9.3p448 : 0.462ms
Ruby 2.0.0-p247: 0.769ms

Any input/guidance would be appreciated. Thanks!
Peter Giacomo Lombardo

--
Posted via http://www.ruby-forum.com/.

--
Tony Arcieri

Eric Wong wrote in post #1115676:

Optimizing data structures (to compact byte code) to speed up common
operations, but makes uncommonly-accessed information (file names, line
numbers) more expensive to access.

I think it's a fair trade to make, caller should not be a
frequently-called method.

Btw, same idea applies to database design, creating indexes will speed
up some operations at the expense of others.

Agreed and understood. My intention was just to identify the cost and
confirm that I wasn't missing something simple. Thanks for the info!

···

--
Posted via http://www.ruby-forum.com/.

Tony Arcieri wrote in post #1115681:

Kernel.caller is very expensive on JRuby too, much more so than MRI.

I'm curious why you're benchmarking it in the first place. `caller' is
not
something you want to be calling very often

On Tue, Jul 16, 2013 at 10:40 AM, Peter Giacomo Lombardo <

Yes - I've noticed the JRuby backtraces are noticeably larger compared
to MRI too.

The benchmark was really just to identify cost of using Kernel.caller.
We selectively use Kernel.caller in AppNeta TraceView's Ruby
instrumentation and wanted updated Ruby 2.0 numbers to backup our
reasoning.

BTW I'm a big fan of Celluloid - great stuff! I've been hacking some
apps with it in my free time.

···

--
Posted via http://www.ruby-forum.com/.