Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster next by reducing number of frame_depth calls #743

Merged
merged 5 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -856,17 +856,23 @@ def wait_next_action_

depth = @target_frames.first.frame_depth

step_tp iter do
loc = caller_locations(2, 1).first
loc_path = loc.absolute_path || "!eval:#{loc.path}"
skip_line = false
step_tp iter do |event|
next if event == :line && skip_line

stack_depth = DEBUGGER__.frame_depth - 3

# If we're at a deeper stack depth, we can skip line events until there's a return event.
skip_line = event == :line && stack_depth > depth

# same stack depth
(DEBUGGER__.frame_depth - 3 <= depth) ||
next true if stack_depth <= depth

loc = caller_locations(2, 1).first
loc_path = loc.absolute_path || "!eval:#{loc.path}"

# different frame
(next_line && loc_path == path &&
(loc_lineno = loc.lineno) > line &&
loc_lineno <= next_line)
next_line && loc_path == path && loc.lineno.between?(line + 1, next_line)
end
break

Expand Down
6 changes: 5 additions & 1 deletion test/console/control_flow_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def program
10|
11| s = Student.new("John")
12| s.name
13| "foo"
13| puts "foo"
14| puts "bar"
15| "baz"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to the test to ensure that next <number> functionality is preserved when stepping over multiple lines at the same stack depth.

RUBY
end

Expand Down Expand Up @@ -84,6 +86,8 @@ def test_next_with_number_goes_to_the_next_nth_line
assert_line_num 11
type 'n 2'
assert_line_num 13
type 'n 2'
assert_line_num 15
type 'quit'
type 'y'
end
Expand Down