Skip to content

Commit

Permalink
Improve Call initialization performance
Browse files Browse the repository at this point in the history
Use an ActorProxy (subclass) instead of a method_missing definition on every Call.new. This considerably improves Call.new performance; benchmarks show approximately a 30-40% improvement: https://gist.github.com/kares/3576e272250204eb66d1
  • Loading branch information
kares authored and benlangfeld committed Feb 27, 2015
1 parent 897b66b commit d189685
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,4 +1,5 @@
# [develop](https://github.com/adhearsion/adhearsion)
* Improve Call initialization performance. Use an ActorProxy (subclass) instead of a method_missing definition on every Call.new. This considerably improves Call.new performance; benchmarks show approximately a 30-40% improvement: https://gist.github.com/kares/3576e272250204eb66d1

# [2.6.0](https://github.com/adhearsion/adhearsion/compare/v2.5.4...v2.6.0) - [2015-02-01](https://rubygems.org/gems/adhearsion/versions/2.6.0)
* Feature: `Call#after_hangup_lifetime` optionally overrides `Adhearsion.config.platform.after_hangup_lifetime` ([#537](https://github.com/adhearsion/adhearsion/pull/537))
Expand Down
21 changes: 11 additions & 10 deletions lib/adhearsion/call.rb
Expand Up @@ -16,22 +16,23 @@ class Call
CommandTimeout = Class.new Adhearsion::Error
ExpiredError = Class.new Celluloid::DeadActorError

# @private
class ActorProxy < Celluloid::ActorProxy
def method_missing(meth, *args, &block)
super(meth, *args, &block)
rescue ::Celluloid::DeadActorError
raise ExpiredError, "This call is expired and is no longer accessible. See http://adhearsion.com/docs/calls for further details."
end
end

include Celluloid
include HasGuardedHandlers

proxy_class Call::ActorProxy

execute_block_on_receiver :register_handler, :register_tmp_handler, :register_handler_with_priority, :register_handler_with_options, :register_event_handler, :on_joined, :on_unjoined, :on_end, :execute_controller, *execute_block_on_receiver
finalizer :finalize

def self.new(*args, &block)
super.tap do |proxy|
def proxy.method_missing(*args)
super
rescue Celluloid::DeadActorError
raise ExpiredError, "This call is expired and is no longer accessible. See http://adhearsion.com/docs/calls for further details."
end
end
end

# @return [Symbol] the reason for the call ending
attr_reader :end_reason

Expand Down

0 comments on commit d189685

Please sign in to comment.