Skip to content

Pauldorsch/reduce linux scan time#1826

Merged
pauld-msft merged 9 commits into
mainfrom
pauldorsch/reduce-linux-scan-duplication
Jun 12, 2026
Merged

Pauldorsch/reduce linux scan time#1826
pauld-msft merged 9 commits into
mainfrom
pauldorsch/reduce-linux-scan-duplication

Conversation

@pauld-msft

@pauld-msft pauld-msft commented Jun 12, 2026

Copy link
Copy Markdown
Member

3 Improvements to Linux Scanning:

  1. The larger boost to perf of the 2, removing the Temp directory binding from the Syft scans
  2. Ensuring that we only pull each image one time
  3. Ensuring that we only run Syft with the same parameters one time

Testing the de-duplication:

dotnet run --project src/Microsoft.ComponentDetection/Microsoft.ComponentDetection.csproj scan --SourceDirectory C:\src\temp --DockerImagesToScan "alpine:3.18,ubuntu:22.04,test-with-base:latest,node:18-bullseye" --LogLevel Debug
Many images, and since there are 2 Linux scanner happening at the same time, we hit the logic that keeps us from trying to pull the same one more than once:
image

we can also confirm that we only see the syft scan happening once per image sha:
image

Testing the performance:

dotnet run --project src/Microsoft.ComponentDetection/Microsoft.ComponentDetection.csproj scan --SourceDirectory C:\src\temp --DockerImagesToScan "node:18-bullseye"

Before, ran in over 400s for node:18-bullseye image (and we also see 2 containers starting up to syft scan this single image):
image

After, ran in under 60s for node:18-bullseye image (and we only see a single container start up to run the syft scan):
image

Copilot AI review requested due to automatic review settings June 12, 2026 19:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce Linux container scanning time by deduplicating expensive Docker/Syft operations across concurrent callers, so the same image/scope work isn’t repeated unnecessarily within a single process run.

Changes:

  • Added a static cache in LinuxScanner to share in-flight (and completed) Syft runs between callers with identical (source, scope, binds).
  • Added a static cache in DockerService to share in-flight (and completed) image pulls between callers for the same image.
  • Added extra debug logging around base image resolution and Docker operations, and reset the Syft cache in tests for isolation.
Show a summary per file
File Description
test/Microsoft.ComponentDetection.Detectors.Tests/LinuxScannerTests.cs Resets the new Syft run cache for test isolation.
src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs Adds Syft run deduplication cache and exposes a test-only reset method.
src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs Adds debug logging for resolved base image details.
src/Microsoft.ComponentDetection.Common/DockerService.cs Adds image pull deduplication cache and adjusts logging/binds.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 5

Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
Copilot AI review requested due to automatic review settings June 12, 2026 20:03
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 5

Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
Copilot AI review requested due to automatic review settings June 12, 2026 21:00
@pauld-msft pauld-msft marked this pull request as ready for review June 12, 2026 21:03
@pauld-msft pauld-msft requested a review from a team as a code owner June 12, 2026 21:03
@pauld-msft pauld-msft requested a review from schmittjoseph June 12, 2026 21:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 12, 2026 21:07
Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread src/Microsoft.ComponentDetection.Common/DockerService.cs
@pauld-msft

Copy link
Copy Markdown
Member Author

👋 Hi! It looks like you modified some files in the Detectors folder. You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

None of these apply, the Detectors return the exact same results

@pauld-msft pauld-msft merged commit 300d88b into main Jun 12, 2026
15 of 16 checks passed
@pauld-msft pauld-msft deleted the pauldorsch/reduce-linux-scan-duplication branch June 12, 2026 23:31
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