Note: this is an in-house item already being handled by the maintainer - not open for contribution. Filed for tracking only.
Measured while reviewing #1114, which adds a stripComments pass to scanAllImports so JSDoc and commented-out imports stop counting as usage. The pass is correct and worth keeping. It is also about 11x slower than what it replaces.
Measured
src/ plus tests/ in this repo, 271 files, 1.9 MB, averaged over 5 passes:
read only (I/O) : 3.2 ms/pass
old extract : 1.2 ms/pass
new extract : 13.0 ms/pass
So the scanning phase goes from roughly 4.4 ms to 16.2 ms, with the extraction step itself about 11x. At the 5,000-file cap that is roughly 240 ms against 22 ms.
Cause
stripComments builds its result with per-character out += ch over the whole file, materialising a second copy of every source file. The pre-filter in scanAllImports (content.includes("import") || "require" || "export") admits essentially every source file, so almost nothing is skipped.
Options
Accumulate chunks in an array and join("") at the end, or compute comment ranges once and filter regex matches by index rather than building a stripped copy at all. The second avoids the allocation entirely and is probably the better shape, since the caller only needs match positions.
Priority
Not urgent. Absolute numbers are small and correctness matters more than the milliseconds here. Filed because #837 (CLI performance audit) is open in P1 and this is a known, measured, cheap-to-fix regression that should be folded into that work rather than rediscovered later.
Should land after #1114 merges, since it modifies code that PR introduces.
Measured while reviewing #1114, which adds a
stripCommentspass toscanAllImportsso JSDoc and commented-out imports stop counting as usage. The pass is correct and worth keeping. It is also about 11x slower than what it replaces.Measured
src/plustests/in this repo, 271 files, 1.9 MB, averaged over 5 passes:So the scanning phase goes from roughly 4.4 ms to 16.2 ms, with the extraction step itself about 11x. At the 5,000-file cap that is roughly 240 ms against 22 ms.
Cause
stripCommentsbuilds its result with per-characterout += chover the whole file, materialising a second copy of every source file. The pre-filter inscanAllImports(content.includes("import") || "require" || "export") admits essentially every source file, so almost nothing is skipped.Options
Accumulate chunks in an array and
join("")at the end, or compute comment ranges once and filter regex matches by index rather than building a stripped copy at all. The second avoids the allocation entirely and is probably the better shape, since the caller only needs match positions.Priority
Not urgent. Absolute numbers are small and correctness matters more than the milliseconds here. Filed because #837 (CLI performance audit) is open in P1 and this is a known, measured, cheap-to-fix regression that should be folded into that work rather than rediscovered later.
Should land after #1114 merges, since it modifies code that PR introduces.