Skip to content

feat: Autoload Twilio::REST and Twilio::HTTP #558

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

Merged
merged 5 commits into from
Jun 24, 2021

Conversation

gmcgibbon
Copy link
Contributor

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:
Screen Shot 2021-06-10 at 12 23 37 PM
After this patch, it did not show up in our profiles.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

Copy link
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

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

Thank you!! Please remove the unnecessary glob.

Copy link
Contributor

@eshanholtz eshanholtz left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for the contribution!

@JenniferMah JenniferMah changed the title Autoload Twilio::REST and Twilio::HTTP feat: Autoload Twilio::REST and Twilio::HTTP Jun 24, 2021
@JenniferMah JenniferMah merged commit ee8f8a7 into twilio:main Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants