Lazy loading modules for faster load times #265
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 untiladmin.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:
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%