diff --git a/lib/diver_down/trace/session.rb b/lib/diver_down/trace/session.rb index c541a18..c2566d5 100644 --- a/lib/diver_down/trace/session.rb +++ b/lib/diver_down/trace/session.rb @@ -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)