summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2015-05-26 16:50:16 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2015-05-27 21:21:24 +0200
commit1bbf8d0720a061e281718f9e6a542da4268160b8 (patch)
tree356d8c326fb5b7189e93b392de732ecb725123c5 /lib/module.js
parentb14fd1a7202cd8001d1f6aed848445bad99ee15c (diff)
downloadandroid-node-v8-1bbf8d0720a061e281718f9e6a542da4268160b8.tar.gz
android-node-v8-1bbf8d0720a061e281718f9e6a542da4268160b8.tar.bz2
android-node-v8-1bbf8d0720a061e281718f9e6a542da4268160b8.zip
lib: speed up require(), phase 2
Replace calls to fs.readFileSync() with an internal variant that does not create Error objects on failure and is a bit speedier in general. A secondary benefit is that it improves start-up times in the debugger because it no longer emits thousands of exception debug events. On a medium-sized application[0], this commit and its predecessor reduce start-up times from about 1.5s to 0.5s and reduce the number of start-up exceptions from ~6100 to 32, half of them internal to the application. [0] https://github.com/strongloop/loopback-sample-app PR-URL: https://github.com/nodejs/io.js/pull/1801 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/module.js b/lib/module.js
index c9e4e2c785..65e44b60b1 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -6,6 +6,7 @@ const runInThisContext = require('vm').runInThisContext;
const assert = require('assert').ok;
const fs = require('fs');
const path = require('path');
+const internalModuleReadFile = process.binding('fs').internalModuleReadFile;
const internalModuleStat = process.binding('fs').internalModuleStat;
@@ -65,10 +66,10 @@ function readPackage(requestPath) {
return packageMainCache[requestPath];
}
- try {
- var jsonPath = path.resolve(requestPath, 'package.json');
- var json = fs.readFileSync(jsonPath, 'utf8');
- } catch (e) {
+ var jsonPath = path.resolve(requestPath, 'package.json');
+ var json = internalModuleReadFile(jsonPath);
+
+ if (json === undefined) {
return false;
}