Commit 83f8d98
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>1 parent 809bf5e commit 83f8d98Copy full SHA for 83f8d98
File tree
Expand file treeCollapse file tree
5 files changed
+62
-6
lines changedOpen diff view settings
Filter options
- lib
- internal
- test
- fixtures/module-require-depth
- parallel
Expand file treeCollapse file tree
5 files changed
+62
-6
lines changedOpen diff view settings
Collapse file
+9-2Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1 | 1 | |
2 | 2 | |
3 | | - |
| 3 | + |
| 4 | + |
| 5 | + |
4 | 6 | |
5 | 7 | |
6 | 8 | |
| ||
9 | 11 | |
10 | 12 | |
11 | 13 | |
12 | | - |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
13 | 20 | |
14 | 21 | |
15 | 22 | |
|
Collapse file
+22-4Lines changed: 22 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
33 | 33 | |
34 | 34 | |
35 | 35 | |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
36 | 50 | |
37 | 51 | |
38 | 52 | |
| ||
114 | 128 | |
115 | 129 | |
116 | 130 | |
117 | | - |
| 131 | + |
118 | 132 | |
119 | 133 | |
120 | 134 | |
| ||
151 | 165 | |
152 | 166 | |
153 | 167 | |
154 | | - |
| 168 | + |
155 | 169 | |
156 | 170 | |
157 | 171 | |
158 | 172 | |
159 | | - |
| 173 | + |
160 | 174 | |
161 | 175 | |
162 | 176 | |
| ||
404 | 418 | |
405 | 419 | |
406 | 420 | |
407 | | - |
| 421 | + |
| 422 | + |
| 423 | + |
| 424 | + |
| 425 | + |
408 | 426 | |
409 | 427 | |
410 | 428 | |
|
Collapse file
test/fixtures/module-require-depth/one.js
Copy file name to clipboard+9Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
Collapse file
test/fixtures/module-require-depth/two.js
Copy file name to clipboard+9Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
Collapse file
test/parallel/test-module-require-depth.js
Copy file name to clipboard+13Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
0 commit comments