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

Improve method breakpoint performance. #703

Merged
merged 1 commit into from
Jul 11, 2022
Merged

Conversation

ko1
Copy link
Collaborator

@ko1 ko1 commented Jul 11, 2022

With pending method breakpoints, track all method invocation to track
method_added and singleton_method_added.
Of course, this approach slows down the debuggee's performance.

This patch tracks all method_added and singleton_method_added methods
and further defined such methods for the classes/modules. This approach
doesn't have performance penalty any more.

This patch also fix the message at registering the pending method
breakpoint.

binding.b do: 'b C#foo' unless ENV['NO_PENDING_BP']

def fib n
  if n<2
    n
  else
    fib(n-1)+fib(n-2)
  end
end

require 'benchmark'

Benchmark.bm{|x|
  x.report{ fib(35) }
}

Results:

Without pending breakpoints:

$ NO_PENDING_BP=1 exe/rdbg -n target.rb
       user     system      total        real
   0.929580   0.000000   0.929580 (  0.929682)

With pending breakpoints - Before this patch:

$ exe/rdbg -n target.rb
[1, 10] in target.rb
=>   1| binding.b do: <<~DBG
     2|   b C#foo
     3| DBG
     4|
     5| def fib n
     6|   if n<2
     7|     n
     8|   else
     9|     fib(n-1)+fib(n-2)
    10|   end
=>#0    <main> at target.rb:1
(rdbg:binding.break) b C#foo
uninitialized constant C

C
^
#0  BP - Method (pending)  C#foo
       user     system      total        real
   3.276217   0.000000   3.276217 (  3.276299)

With pending breakpoints - After this patch:

[master]$ exe/rdbg -n target.rb
[1, 10] in target.rb
=>   1| binding.b do: <<~DBG
     2|   b C#foo
     3| DBG
     4|
     5| def fib n
     6|   if n<2
     7|     n
     8|   else
     9|     fib(n-1)+fib(n-2)
    10|   end
=>#0    <main> at target.rb:1
(rdbg:binding.break) b C#foo
Unknown name `C` for `Object`
#0  BP - Method (pending)  C#foo
       user     system      total        real
   0.933402   0.002353   0.935755 (  0.935757)

def singleton_method_added mid; end
end

def self.method_added_tracekr_create mod, method_added_id, method_accessor = :method
Copy link
Member

Choose a reason for hiding this comment

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

Should this be method_added_tracker_create instead?

end
end

def self.method_added_tracekr_activate
Copy link
Member

Choose a reason for hiding this comment

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

method_added_tracker_activate?
I'd also recommend putting the verb activate in front of the method. So it'd be activate_method_added_tracker.

end
end

def self.method_added_tracekr_deactivate
Copy link
Member

Choose a reason for hiding this comment

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

method_added_tracker_deactivate?

With pending method breakpoints, track all method invocation to track
`method_added` and `singleton_method_added`.
Of course, this approach slows down the debuggee's performance.

This patch tracks all `method_added` and `singleton_method_added` methods
and further defined such methods for the classes/modules. This approach
doesn't have performance penalty any more.

This patch also fix the message at registering the pending method
breakpoint.

```ruby

binding.b do: 'b C#foo' unless ENV['NO_PENDING_BP']

def fib n
  if n<2
    n
  else
    fib(n-1)+fib(n-2)
  end
end

require 'benchmark'

Benchmark.bm{|x|
  x.report{ fib(35) }
}
```

Results:

```
Without pending breakpoints:

$ NO_PENDING_BP=1 exe/rdbg -n target.rb
       user     system      total        real
   0.929580   0.000000   0.929580 (  0.929682)

With pending breakpoints - Before this patch:

$ exe/rdbg -n target.rb
[1, 10] in target.rb
=>   1| binding.b do: <<~DBG
     2|   b C#foo
     3| DBG
     4|
     5| def fib n
     6|   if n<2
     7|     n
     8|   else
     9|     fib(n-1)+fib(n-2)
    10|   end
=>#0    <main> at target.rb:1
(rdbg:binding.break) b C#foo
uninitialized constant C

C
^
       user     system      total        real
   3.276217   0.000000   3.276217 (  3.276299)

With pending breakpoints - After this patch:

[master]$ exe/rdbg -n target.rb
[1, 10] in target.rb
=>   1| binding.b do: <<~DBG
     2|   b C#foo
     3| DBG
     4|
     5| def fib n
     6|   if n<2
     7|     n
     8|   else
     9|     fib(n-1)+fib(n-2)
    10|   end
=>#0    <main> at target.rb:1
(rdbg:binding.break) b C#foo
Unknown name `C` for `Object`
       user     system      total        real
   0.933402   0.002353   0.935755 (  0.935757)
```
@ko1 ko1 force-pushed the improve_method_bp_performance branch from 319cd2e to c390872 Compare July 11, 2022 08:37
@ko1
Copy link
Collaborator Author

ko1 commented Jul 11, 2022

Thank you for the typo report. I fixed it.

I'd also recommend putting the verb activate in front of the method. So it'd be activate_method_added_tracker

The name foo_create foo_activate I intended that the receiver is foo, but it seems confusing. fixed.

@st0012
Copy link
Member

st0012 commented Jul 11, 2022

The name foo_create foo_activate I intended that the receiver is foo, but it seems confusing. fixed.

It's not confusing. But in English we usually say activate the breakpoint or install the gem. So naming methods as verb_the_receiver like active_method_added_tracker reads closer to that.

@ko1 ko1 merged commit 296daa6 into master Jul 11, 2022
@ko1 ko1 deleted the improve_method_bp_performance branch July 11, 2022 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants