Skip to content

Commit

Permalink
Optimize the maximum value going back caller_location
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Apr 24, 2024
1 parent 069bbf1 commit 7603df8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/diver_down/trace/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ def build_trace_point
end
end

# `caller_location` is nil if it is filtered by target_files
caller_location = find_neast_caller_location(call_stack.stack_size)
# Search is a heavy process and should be terminated early.
# The position of the most recently found caller or the start of trace is used as the maximum value.
maximum_back_stack_size = if call_stack.empty_context_stack?
call_stack.stack_size
else
call_stack.stack_size - call_stack.context_stack_size[-1]
end

caller_location = find_neast_caller_location(maximum_back_stack_size)

# `caller_location` is nil if it is filtered by target_files
if caller_location
pushed = true
source = @definition.find_or_build_source(source_name)
Expand Down

0 comments on commit 7603df8

Please sign in to comment.