@@ -173,6 +173,69 @@ Hyperfine measurements show a ~7-12% improvement in lint time:
173173| Baseline | 3.112 s ± 0.033 s | 4.382 |
174174| Caching | 2.740 s ± 0.030 s | 4.032 |
175175
176+ ### Comparison: Project Service Uncached File System Path Reads
177+
178+ This comparison shows the cost uncached ` fs.realpath ` calls inside the project service.
179+ It also was run on a common shape of linting: 1024 files with the "even" (triangle-shaped) imports layout.
180+
181+ See ` traces/service-uncached-realpaths/ ` :
182+
183+ - ` baseline.cpuprofile ` : Baseline measurement with no changes
184+ - ` caching.cpuprofile ` : Adding a caching ` Map ` to TypeScript's ` realpath `
185+
186+ They were generated with:
187+
188+ ``` shell
189+ cd files-1024-layout-even-singlerun-true-types-service
190+ node --cpu-prof --cpu-prof-interval=100 --cpu-prof-name=baseline.cpuprofile ../../node_modules/eslint/bin/eslint.js
191+ # edit ../../node_modules/typescript/lib/typescript.js > realpath (see diff below)
192+ node --cpu-prof --cpu-prof-interval=100 --cpu-prof-name=caching.cpuprofile ../../node_modules/eslint/bin/eslint.js
193+ ```
194+
195+ <details >
196+ <summary ><code >diff</code > patch to switch to the <em >Caching</em > variant...</summary >
197+
198+ ``` diff
199+ diff --git a/node_modules/typescript/lib/typescript.js b/node_modules/typescript/lib/typescript.js
200+ index 4baad59..e53476d 100644
201+ --- a/node_modules/typescript/lib/typescript.js
202+ +++ b/node_modules/typescript/lib/typescript.js
203+ @@ -13,6 +13,8 @@ See the Apache Version 2.0 License for specific language governing permissions
204+ and limitations under the License.
205+ ***************************************************************************** */
206+
207+ + var realpathCache = new Map();
208+ +
209+ var ts = {}; ((module) => {
210+ "use strict";
211+ var __defProp = Object.defineProperty;
212+ @@ -8798,6 +8800,15 @@ var sys = (() => {
213+ return path.length < 260 ? _fs.realpathSync.native(path) : _fs.realpathSync(path);
214+ }
215+ function realpath(path) {
216+ + const cached = realpathCache.get(path);
217+ + if (cached) {
218+ + return cached;
219+ + }
220+ + const result = realpathWorker(path);
221+ + realpathCache.set(path, result);
222+ + return result;
223+ + }
224+ + function realpathWorker(path) {
225+ try {
226+ return fsRealpath(path);
227+ } catch {
228+ ```
229+
230+ </details >
231+
232+ Hyperfine measurements show a ~ 0.5-2.5% improvement in lint time:
233+
234+ | Variant | Measurement | User Time |
235+ | -------- | ----------------- | --------- |
236+ | Baseline | 3.153 s ± 0.039 s | 4.403 s |
237+ | Caching | 3.073 s ± 0.048 s | 4.377 s |
238+
176239## Contributors
177240
178241<!-- spellchecker: disable -->
0 commit comments