Currently Twilio::REST and Twilio::HTTP are loaded with file globs. This works great, but it is slow. Especially for Twilio::REST which has lots of files. For applications using this gem, bundler will require "twilio-ruby" and load the entire gem at once.
Ruby's autoload feature can help with this. Autoload defers loading modules until they are actually needed/referenced. By autoloading Twilio::REST and Twilio::HTTP, the require-time of this library is reduced from ~400ms to ~25ms. You can verify this by wrapping the require in your spec helper with a benchmark block:
require "benchmark"
ms = 1000 * Benchmark.realtime do
require 'twilio-ruby'
end
puts "Require took #{ms}ms"
This is what the gem require currently looks like in our application, with the majority of time taken by requiring Twilio::REST:
After this patch, it did not show up in our profiles.
Checklist
[x] I acknowledge that all my contributions will be made under the project's license
[x] I have made a material change to the repo (functionality, testing, spelling, grammar)
Currently
Twilio::REST
andTwilio::HTTP
are loaded with file globs. This works great, but it is slow. Especially forTwilio::REST
which has lots of files. For applications using this gem, bundler willrequire "twilio-ruby"
and load the entire gem at once.Ruby's
autoload
feature can help with this. Autoload defers loading modules until they are actually needed/referenced. By autoloadingTwilio::REST
andTwilio::HTTP
, the require-time of this library is reduced from~400ms
to~25ms
. You can verify this by wrapping the require in your spec helper with a benchmark block:This is what the gem require currently looks like in our application, with the majority of time taken by requiring
Twilio::REST
:After this patch, it did not show up in our profiles.
Checklist
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.