-
Notifications
You must be signed in to change notification settings - Fork 640
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
Prevent optional dependency Chokidar from loading when not watching #1250
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1250 +/- ##
==========================================
- Coverage 89.6% 89.53% -0.07%
==========================================
Files 22 22
Lines 3020 3020
==========================================
- Hits 2706 2704 -2
- Misses 314 316 +2
Continue to review full report at Codecov.
|
As you can see from this trace, a require('nunjucks') call takes (on my system) ~177ms, of which ~160ms is spent on importing chokidar, even when watch is set to false. With this change, nunjucks takes only ~17ms to load. Every little bit helps. ;)
|
LGTM. I've merged this. Thanks! |
Cool! 👍 |
Summary
Proposed change:
Since Chokidar is an optional dependency, and relatively heavy, it would be best to defer requiring it until the watcher is actually needed. This gives a slight speed increase when using FileSystemResolver or NodeResolver with the watch option set to false, unless the end-user has already loaded Chokidar.
Triggering require() twice when using both loaders does not have a big performance impact because of the module cache. This is an internal change only. I have not written tests, since these would depend upon module.cache[] side-effects to run.
Checklist
I've completed the checklist below to ensure I didn't forget anything. This makes reviewing this PR as easy as possible for the maintainers. And it gets this change released as soon as possible.