Commit 77427b7
perf: Reduce and parallelize file system operations in the module state scan
ModuleStateBuilder.buildModuleState walks the entire node_modules tree
on every ComponentsManager build (1,381 modules for a Community Solid
Server install). Three refinements, none of which change the resulting
module state:
1. buildNodeModulePathsInner awaited the recursion for each non-scoped
dependency sequentially, while scoped dependencies were already
handled with Promise.all. Both now recurse in parallel. (The
ignorePaths check-and-set is synchronous after the realpath await,
so deduplication is unaffected.)
2. buildPackageJsons performed a stat (fileExists) followed by a
readFile for every module; it now reads directly and treats a read
failure as "no package.json", halving the file system operations of
the hottest phase (1,381 -> 0 extra stats). Malformed JSON still
throws exactly as before.
3. preprocessPackageJson probed components/components.jsonld,
components/context.jsonld, components/ and config/ with four
sequential stats per lsd:module package; the probes now run in
parallel.
A/B against the real Community Solid Server node_modules tree
(1,381 modules, warm file system cache, 9 reps, 2-core shared box,
alternating arms in the same run):
before: median 355 ms (min 324)
after: median 259-267 ms (min 236) ~1.35x, -90 ms per boot
The resulting module state is identical in both arms
(1,381 nodeModulePaths / 1,381 packageJsons / 168 componentModules /
169 contexts / 175 importPaths). The gain grows with cold file caches,
where the parallel recursion overlaps disk latency instead of paying it
serially.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 0512b9a commit 77427b7
1 file changed
Lines changed: 38 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
158 | | - | |
159 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
160 | 167 | | |
| 168 | + | |
161 | 169 | | |
162 | 170 | | |
163 | 171 | | |
| |||
181 | 189 | | |
182 | 190 | | |
183 | 191 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | 192 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
197 | 201 | | |
198 | | - | |
199 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
200 | 216 | | |
201 | 217 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 218 | + | |
| 219 | + | |
208 | 220 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 221 | + | |
| 222 | + | |
215 | 223 | | |
216 | 224 | | |
217 | 225 | | |
| |||
0 commit comments