Skip to content

Speed up secret scanning by turning off Secretlint's profiler - #1352

Merged
Benjamin Christopher Simmonds (benibenj) merged 3 commits into
microsoft:mainfrom
bschnurr:perf/secretlint-profiler
Nov 24, 2026
Merged

Benjamin Christopher Simmonds (benibenj) merged 3 commits into
microsoft:mainfrom
bschnurr:perf/secretlint-profiler

Conversation

@bschnurr

@bschnurr Bill Schnurr (bschnurr) commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Before: Packaging an extension with many files spent most of its time scanning for secrets. Secretlint's built-in profiler recorded performance marks for every file and every rule, and each new mark searched through all earlier ones, so scan time grew roughly with the square of the file count. vsce never reads those measurements.

After: vsce upgrades Secretlint's core to 13.1.0 and turns its profiler off, so scan time grows linearly with the number of files. Which secrets get detected doesn't change: the detection rules stay at the version vsce uses today.

Measured locally (macOS, Apple Silicon, Node 24), with extensions made of VS Code source files:

main this PR
vsce package, 2,048 files (median of 3) 11.8 s 1.5 s
Secret scan only, 8,192 files 174 s 1.1 s
Secret scan of 31 real extensions (9,892 files) 70.6 s 9.4 s

This is part 1 of splitting the original change. The detection-rule upgrade moved to #1358, and the move to Secretlint v14 is in draft #1359.

Details

Changes

  • @secretlint/core, source-creator, types and secretlint-rule-no-dotenv go from 10.2.2 to 13.1.0. For vsce they behave the same in both versions: the only source change in core is a fix to secret masking, which vsce doesn't use.
  • @secretlint/secretlint-rule-preset-recommend stays at 10.2.2. All detection logic lives in that package, so findings are identical.
  • vsce calls secretLintProfiler.setEnabled(false) (available since 13.0.7) before scanning. The profiler is loaded from @secretlint/core's own location, so the switch always reaches the instance core uses, even when npm installs a second copy of the profiler somewhere else in the tree.
  • Profiler 13.x already replaced the linear search through earlier marks with a set lookup. Turning it off also removes the remaining cost of creating marks and running the performance observer.

Side effects

  • The Secretlint packages now require Node 22 or later, which vsce already requires.
  • Other performance.mark users in the same process are unaffected; a test checks this.
  • npm shows a deprecation warning for preset-recommend at install, because upstream deprecated every version. That's unchanged here; the v14 draft removes the package.

Testing

  • npm test: 404 passing. The new tests force the profiler on, run real file and in-memory scans, and check that no Secretlint marks or measures are recorded while findings are still reported. They fail if the switch is removed.
  • Same findings as main for 42 hand-written samples (private keys in many formats; npm, GitHub, OpenAI and Slack tokens; .env files) and for all 9,892 files of 31 real extensions.
  • Debugged a real vsce package run on 2,048 files with dbgjs. In the live process, core's profiler instance reports isEnabled: false and never starts its observer. After scanning, main had recorded 73,800 Secretlint marks and 36,864 measures and spent about 11.5 s of a 15 s CPU profile inside the profiler's observer; this PR recorded none and has no profiler frames.
  • Installed the packed tarball next to a conflicting top-level @secretlint/[email protected]. npm nested core's own copy, and scanning still recorded no marks.

Upgrade Secretlint packages to 13.1.0 and disable internal profiling before file and in-memory scans. Preserve secret detection with realistic fixtures and regression coverage for profiling, disabled scanning, and updated rules.

Co-authored-by: Copilot <[email protected]>
Comment thread src/secretLint.ts Resolved
@bschnurr Bill Schnurr (bschnurr) changed the title Avoid unused Secretlint profiling during packaging Speed up packaging 7.9x with Secretlint upgrade and profiling disabled Nov 3, 2026
@bschnurr

Copy link
Copy Markdown
Member Author

Resolve the dependency manifest and lockfile conflicts while keeping both branches' updates.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c6702bc7-8e98-4ab3-99ba-07d071bc50f5
@benibenj

Benjamin Christopher Simmonds (benibenj) commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Thanks Bill, the speedup is great. I could reproduce it locally: scanning ~8k files went from ~260 s to ~4 s.

The jump to Secretlint 13.1.0 also changes which secrets get caught, though:

  • EC (BEGIN EC PRIVATE KEY), Ed25519 and encrypted private keys are no longer detected.
  • The 15 new detectors also flag placeholders, like database URLs with <password>, so some extensions that package fine today would fail (for example Prisma).

To get the speedup in quickly, I split this up:

  1. This PR: speedup only. I pushed a commit that keeps the recommended rules at 10.2.2, so findings stay the same.
  2. Detect more kinds of secrets when packaging (Secretlint 13.1.0 rules) #1358: upgrade the rules, keep catching those private keys, and allow placeholder database URLs.
  3. Scan for secrets faster with Secretlint v14 #1359 (draft): move to Secretlint v14, where profiling is off by default.

Your branch allows maintainer edits, so I pushed the change there and updated the description.

Hold @secretlint/secretlint-rule-preset-recommend at 10.2.2 so this change only affects scanning speed: every detection rule lives in that package, and core, source-creator, types and no-dotenv behave the same in 13.1.0. The rule upgrade moves to a separate PR.

Load the profiler from @secretlint/core's own location instead of declaring it as a direct dependency, so disabling it always reaches the instance core uses.

Co-authored-by: Copilot <[email protected]>
@benibenj Benjamin Christopher Simmonds (benibenj) changed the title Speed up packaging 7.9x with Secretlint upgrade and profiling disabled Speed up secret scanning by turning off Secretlint's profiler Nov 23, 2026
@benibenj
Benjamin Christopher Simmonds (benibenj) merged commit a2a8745 into microsoft:main Nov 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants