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

feat: Faster requiring using optional lazy loading #526

Merged
merged 2 commits into from Feb 25, 2020

Conversation

wolfenrain
Copy link
Contributor

@wolfenrain wolfenrain commented Feb 6, 2020

Fixes #525

I have done some tweaking and added a proof of concept lazy loading to the Twilio module to see if it improves the loading time, see the compare for reference.

When lazy loading is disabled(default), test returns a 600ms timeframe:

console.time('Twilio');
const Twilio = require('./index');
const client = new Twilio('AAAAAAAAAAAAAAAAAAAAAAAA', 'AUTHTOKEN');
console.timeEnd('Twilio');

When lazy loading is enabled, test returns a 16ms timeframe:

console.time('Twilio');
const Twilio = require('./index');
const client = new Twilio('AAAAAAAAAAAAAAAAAAAAAAAA', 'AUTHTOKEN', { lazyLoading: true });
console.timeEnd('Twilio');

The require of Twilio has been changed slightly for the initializer, instead of auto requiring everything, I made it into getter. This already gave a small increase. But the biggest change was removing all the requires from Twilio.js. I moved those to getters as well.

And the requiring of the RestClient.js is also a big time consumer, so I made a getter for that as well.

Problem is that the Twilio.js file is automatically generated.. but my compare should at least show that certain optimizations are possible. It would be great if the code generator is able to generate these optimizations.

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)
  • [ x ] I have read the Contribution Guidelines and my PR follows them
  • [ x ] I have titled the PR appropriately
  • [ x ] I have updated my branch with the master branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added 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.

@childish-sambino childish-sambino changed the title Faster requiring using optional lazy loading feat: Faster requiring using optional lazy loading Feb 25, 2020
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.

Looks good! Thanks for the contribution. We'll be including your changes in the next release of twilio-node scheduled for 2020-03-04.

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.

Slow require/import on serverless functions
2 participants