Issue #7434 has been updated by sam.saffron (Sam Saffron).


> My question is: use-case of negative number for performance. Your answer only shows "backtrace is big".

Apologies, well for MiniProfiler ( https://github.com/SamSaffron/MiniProfiler/tree/master/Ruby ) we gather stack traces quite aggressively, every time a query is execute a backtrace is materialized. 

A classic place of where I would like to cut down on backtrace overhead is the sampling profiler see: https://github.com/SamSaffron/MiniProfiler/blob/master/Ruby/lib/mini_profiler/profiler.rb#L289 

Another use case would be a user option for :application_trace_only, that would figure out how many frames to skip in the first SQL interception and store that on the Thread so following calls to grab stack traces only include the "application" section and the framework stuff is not gathered. 

The seek is still cheaper than materializing all the strings for the filenames and so on just to discard.


----------------------------------------
Feature #7434: Allow caller_locations and backtrace_locations to receive negative params
https://bugs.ruby-lang.org/issues/7434#change-34014

Author: sam.saffron (Sam Saffron)
Status: Assigned
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: next minor


Further to http://bugs.ruby-lang.org/issues/7051 

It would be nice if caller_locations and backtrace_locations has some parity with range apis.

pry(main)> [1,2,3][0..-2]
=> [1, 2]

Similarly: 

caller_locations(0,-2) # should strip the bottom frame 

This is actually quite important for diagnostics of Rails and other frameworks where the app code starts at a very deep frame. 

At the moment you are forced to materialize all frames just to discard. 







-- 
http://bugs.ruby-lang.org/