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

Lazy loading modules for faster load times #265

Merged
merged 2 commits into from
May 14, 2018
Merged

Conversation

hiranya911
Copy link
Contributor

Lazy loading internal modules and some dependencies for faster load times. This essentially defers loading child modules until they are explicitly required (using the technique described here). For example none of the auth/* sources will be loaded until admin.auth() is invoked. This also ensures that only the child modules used by the developers get loaded into the Node.js process.

Experimental results

Test code:

const start = Date.now();
require('firebase-admin');
const end = Date.now();
console.log('Load time:', (end-start), 'ms');

MacBook Pro (Core i7 2.2 GHz, 16GB RAM)

Before (ms): 154, 151, 151, 153, 153 (mean = 152.4ms)
After (ms): 18, 18, 17, 18, 18 (mean = 17.8ms)
Speed up of initial load: 88.32%

Ubuntu 16.04 (Core i7 2.8GHz, 16GB RAM)

Before (ms): 61, 59, 59, 59, 59 (mean = 59.4 ms)
After (ms): 4, 5, 5, 4, 5 (mean = 4.6 ms)
Speed up of initial load: 92.25%

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

The change LGTM. Can you split out the package-lock.json changes? Changing how we load modules should not affect our package-lock and I don't want to give off the impression that it does.

@hiranya911
Copy link
Contributor Author

Done. Removed package-lock changes from the PR.

Also FYI @laurenzlong. I think Functions is likely to be the biggest beneficiary of this change.

@hiranya911 hiranya911 merged commit a27ea96 into master May 14, 2018
@hiranya911 hiranya911 deleted the hkj-lazy-loading branch May 14, 2018 18:18
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.

2 participants