From 7603df82924786b687b2b351fd29fc1e396a392d Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Mon, 22 Apr 2024 23:49:26 +0900 Subject: [PATCH] Optimize the maximum value going back caller_location --- lib/diver_down/trace/session.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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)