Skip to content

Commit 2dfad35

Browse files
authored
Merge pull request #268 from applandinc/sw/faster_trace_end_hook
Optimize `config.lookup_package` check in `trace_end`
2 parents f2d313b + bd012b0 commit 2dfad35

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/appmap/hook.rb

+10-9
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ def trace_end(trace_point)
183183

184184
hook = lambda do |hook_cls|
185185
lambda do |method_id|
186-
# Don't try and trace the AppMap methods or there will be
187-
# a stack overflow in the defined hook method.
188-
next if %w[Marshal AppMap ActiveSupport].member?((hook_cls&.name || '').split('::')[0])
189-
190-
next if method_id == :call
191-
192186
method = \
193187
begin
194188
hook_cls.instance_method(method_id)
@@ -197,6 +191,16 @@ def trace_end(trace_point)
197191
next
198192
end
199193

194+
package = config.lookup_package(hook_cls, method)
195+
# doing this check first returned early in 98.7% of cases in sample_app_6th_ed
196+
next unless package
197+
198+
# Don't try and trace the AppMap methods or there will be
199+
# a stack overflow in the defined hook method.
200+
next if %w[Marshal AppMap ActiveSupport].member?((hook_cls&.name || '').split('::')[0])
201+
202+
next if method_id == :call
203+
200204
next if self.class.already_hooked?(method)
201205

202206
warn "AppMap: Examining #{hook_cls} #{method.name}" if LOG
@@ -206,9 +210,6 @@ def trace_end(trace_point)
206210
# TODO: Figure out how to tell the difference?
207211
next unless disasm
208212

209-
package = config.lookup_package(hook_cls, method)
210-
next unless package
211-
212213
package.handler_class.new(package, hook_cls, method).activate
213214
end
214215
end

0 commit comments

Comments
 (0)