-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: cache stat() results more aggressively
Reduce the number of stat() system calls that require() makes by caching the results more aggressively. To avoid unbounded growth without implementing a LRU cache, scope the cache to the lifetime of the first call to require(). Recursive calls (i.e. require() calls in the included code) transparently profit from the cache. The benchmarked application is the loopback-sample-app[0] and it sees the number of stat calls at start-up go down by 40%, from 4736 to 2810. [0] https://github.com/strongloop/loopback-sample-app PR-URL: #4575 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
809bf5e
commit 83f8d98
Showing
5 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Flags: --expose_internals | ||
'use strict'; | ||
const assert = require('assert'); | ||
const internalModule = require('internal/module'); | ||
|
||
exports.requireDepth = internalModule.requireDepth; | ||
assert.strictEqual(internalModule.requireDepth, 1); | ||
assert.deepStrictEqual(require('./two'), { requireDepth: 2 }); | ||
assert.strictEqual(internalModule.requireDepth, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Flags: --expose_internals | ||
'use strict'; | ||
const assert = require('assert'); | ||
const internalModule = require('internal/module'); | ||
|
||
exports.requireDepth = internalModule.requireDepth; | ||
assert.strictEqual(internalModule.requireDepth, 2); | ||
assert.deepStrictEqual(require('./one'), { requireDepth: 1 }); | ||
assert.strictEqual(internalModule.requireDepth, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Flags: --expose_internals | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const internalModule = require('internal/module'); | ||
|
||
// Module one loads two too so the expected depth for two is, well, two. | ||
assert.strictEqual(internalModule.requireDepth, 0); | ||
const one = require(common.fixturesDir + '/module-require-depth/one'); | ||
const two = require(common.fixturesDir + '/module-require-depth/two'); | ||
assert.deepStrictEqual(one, { requireDepth: 1 }); | ||
assert.deepStrictEqual(two, { requireDepth: 2 }); | ||
assert.strictEqual(internalModule.requireDepth, 0); |